Skip to content

Instantly share code, notes, and snippets.

@JarvisTheAvenger
Created August 9, 2021 11:25
Show Gist options
  • Save JarvisTheAvenger/a8a3fa6d9ed39bf50908810be6dfeadf to your computer and use it in GitHub Desktop.
Save JarvisTheAvenger/a8a3fa6d9ed39bf50908810be6dfeadf to your computer and use it in GitHub Desktop.
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