Reputation: 69
I'm using NSOperationQueue for the fetching the photos for the device. When i go back i'm calling
[queue cancelAllOperations];
[queue waitUntilAllOperationsAreFinished];
these line to cancel the operation. Operations are cancels well, but its taking some time delay in going back to previous page.
How to reduce the time delay. Thanks in advance
Upvotes: 1
Views: 225
Reputation: 1692
cancelAllOperations doesn't immediately cancel a currently executing NSOperation, it only sends it the cancel message (refer to the docs). It's up to you to periodically check if the operation has been cancelled. For example:
if (!self isCancelled) {
// continue executing
}
Alternatively you can up a Key Value Observer to monitor for the -cancel signal (example of that here).
As a side note, calling "waitUntilAllOperationsAreFinished" after "cancelAllOperations" is redundant. Since you call cancelAllOperations first, it should return immediately.
Finally, I highly recommend if you haven't already, to read the Concurrency Programming Guide. Multi-threading is a very complex but invaluable tool for programming, it helped me greatly to understand the principles of the Objective-C implementation.
Upvotes: 1