Re: NSOperation and waitUntilFinished
Re: NSOperation and waitUntilFinished
- Subject: Re: NSOperation and waitUntilFinished
- From: Koen van der Drift <email@hidden>
- Date: Sat, 20 Oct 2012 21:46:36 -0400
On Sat, Oct 20, 2012 at 2:55 PM, Jonathan Hull <email@hidden> wrote:
> You probably want to be using -addDependency:
>
> -waitUntilAllOperationsAreFinished just blocks the thread it is called on until the receiver finishes (thus if you call it on the same thread as the queue, it will block it forever).
Thanks, I think that is what called a deadlock?
>
> If you need to do something after the operation is done which is not an operation itself, then you probably want to look at -setCompletionBlock:. The block you provide will get called once the operation is complete (and let you clean things up, etc…). Note that the block may not be called on the main thread.
Inside my NSOperation, I need to call executeFetchRequest on the main
thread to query the main context to see if certain entities already
exist (to avoid adding duplicates). I'll look into adding another
operation to do some subsequent work and make that a dependency of the
first operation. That way I can avoid using waitUntilFinished, and
prevent the deadlock.
- Koen.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden