-
Notifications
You must be signed in to change notification settings - Fork 13
Description
For my own project I also ported the Apple example code from Swift over to Objective-C. I've noticed a fundamental issue however with Apple's implementation of the NSOperation subclass. I wonder, if anyone following this project can confirm my issue:
I think the cancel method is handled incorrectly. The documentation states, that an operation that has been cancelled, should stop its execution and eventually return YES when asked isFinished and NO when asked isExecuting.
In Apple's example code the operation's internal state is set to Cancelled when cancel is invoked. So far so good. However, the method setState: defines Cancelled as a fixed state that cannot be changed. Moreover isFinished will return YES only if state == Finished. This means that a cancelled operation can never report that it is finished.
This behavior can be a serious problem when an operation is added to an operation queue and cancelled during execution. Since the operation will never reach the Finished state, the queue will not remove the operation. In a serial queue this can cause the queue to stall. Subsequent operations will never start.