I would like to understand what is the correct behavior for an NSOperation
subclass.
I have my subclasses with different isReady
conditions. Yes, I check in the code if the operation is cancelled and I act in consequence. This is great while the operation is in execution. It stops its task, sets finished
to true and it gets deleted from the queue. But what about its dependencies? They are not yet executing, so they stay in the NSOperationQueue
in cancelled
state forever.
Should I set ready = true
for cancelled operations so the queue will call the start method that will set in executing and immediately finish the task setting finished
to true?
The dependent operation will be executed. No matter a
is cancelled or not.
You should set operation.finished==true
at the final state to make NSOperationQueue
removes the operation
.
You should set .ready==true
whenever it's ready to begin the operation
.
In life cycle of operation
, you should frequently check .cancelled
whenever .cancelled == true
, you should stop operation
and set .finished == true
.