Referring https://developer.apple.com/reference/foundation/operation, I am having Playground setup as -
class myOperation1 : Operation {
override func main() {
print("op1 working....")
}
}
class myOperation2 : Operation {
override func main() {
print("op2 working....")
}
}
let op1 = myOperation1()
let op2 = myOperation2()
op1.completionBlock = {
print("op1 finished")
}
op2.completionBlock = {
print("op2 finished")
}
op2.addDependency(op1)
let opsQue = OperationQueue()
opsQue.addOperation(op1)
opsQue.addOperation(op2)
And console log is -
op1 working....
op2 working....
op1 finished
op2 finished
Shouldn't we expect output as result of dependency? -
op1 working....
op1 finished
op2 working....
op2 finished
Same result with using - opsQue.addOperations([op1, op2], waitUntilFinished: true)
op1 working....
op2 working....
op1 finished
op2 finished
opsQue.addOperations([op1, op2], waitUntilFinished: true)
– Commanderprint
gets placed in the console relative to the output produced byprint
of the worker thread. Note that severalprint
functions called from different threads may get serialised. This means, all what you are experiencing is expected. – Incipit