Skip to content

Instantly share code, notes, and snippets.

@reejosamuel
Created October 17, 2017 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reejosamuel/5502b7be9f7749fc8af44dab7072e646 to your computer and use it in GitHub Desktop.
Save reejosamuel/5502b7be9f7749fc8af44dab7072e646 to your computer and use it in GitHub Desktop.
Operation and Dispatch queue executions
let queue1 = DispatchQueue(label: "com.reejo.test",
qos: .userInitiated,
attributes: .concurrent,
autoreleaseFrequency: .inherit,
target: DispatchQueue.global())
queue1.async {
print("welcome!")
}
let operationQueue = OperationQueue()
let blockOperation = BlockOperation {
print("Welcome on BlockOperation")
}
blockOperation.queuePriority = .low
blockOperation.qualityOfService = .background
let dependentOperation = BlockOperation {
print("Pre block operation")
}
dependentOperation.queuePriority = .veryLow
dependentOperation.qualityOfService = .background
let plainOperation = Operation()
plainOperation.completionBlock = {
print("plain operation depending on none")
}
plainOperation.queuePriority = .veryHigh
blockOperation.addDependency(dependentOperation)
operationQueue.addOperation(blockOperation)
operationQueue.addOperation(dependentOperation)
operationQueue.addOperation(plainOperation)
// welcome!
// Pre block operation
// plain operation depending on none
// Welcome on BlockOperation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment