In a simple case operation2 is dependent on operation1, however operation1 may fail and in this case we don't want to execute operation2
is it possible to deliver a failed execution inside the operation1 code block? so that operation1 fails to complete and operation2 never gets executed and is disposed?
let operation1 = BlockOperation {
// do smth, which can fail
}
let operation2 = BlockOperation {
}
operation2.addDependency(operation1)
You have to cancel the dependent operations manually. An
Operationhas adependenciesarray containing all the operations depending on the operation. In the place inoperation1that you detect failure, cycle through thedependenciesarray and callcancel()on each of the operations in the array.Calling
cancel()is not always enough to actually cancel an operation. The general setup is that the beginning of thestart()function checks theisCancelledboolean and if it'strue, returns without executing the task. So the operation "executes" but doesn't do the actual work. If you've overriddenstart()you will have to do this yourself.All of this needs to be done before
isFinishedis set totrue.