Created
August 9, 2021 11:25
-
-
Save JarvisTheAvenger/a8a3fa6d9ed39bf50908810be6dfeadf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//OperationQueue | |
class RawMaterialImporter: Operation { | |
override func main() { | |
guard !self.isCancelled else { return } | |
print("raw material importing started...") | |
sleep(4) | |
} | |
} | |
class CarMaker: Operation { | |
override func main() { | |
guard !self.isCancelled else { return } | |
print("car making started...") | |
} | |
} | |
let operationQueue = OperationQueue() | |
operationQueue.maxConcurrentOperationCount = 1 | |
let importOperation = RawMaterialImporter() | |
let carMakingOperation = CarMaker() | |
carMakingOperation.completionBlock = { | |
print("car making completed...") | |
} | |
importOperation.completionBlock = { | |
print("importing completed...") | |
} | |
operationQueue.addOperation(importOperation) | |
operationQueue.addOperation(carMakingOperation) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment