NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:
NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:
- Subject: NSOperationQueue: -waitUntilAllOperationsAreFinished and -setSuspended:
- From: Kyle Sluder <email@hidden>
- Date: Sat, 01 Oct 2011 15:06:29 -0700
Hi all,
Can't find an answer to this in the documentation. Does
-waitUntilAllOperationsAreFinished pay heed to the -isSuspended state
of the NSOperationQueue? I ask because I'm basically following this
pattern to collect responses from multiple concurrent background
operations in a thread-safe way.:
NSOperationQueue backgroundQueue = /* some long-lived background queue */;
NSOperationQueue replyQueue = [NSOperationQueue new];
int totalResult = 0;
[replyQueue setSuspended:YES];
for (id foo in myFoos) {
[backgroundQueue addOperationWithBlock:^{
int result = DoSomething();
[replyQueue addOperationWithBlock:^{
totalResult += result;
}];
}];
}
[replyQueue waitUntilAllOperationsAreFinished];
/* all done! */
But this falls apart if -waitUntilAllOperationsAreFinished doesn't
look at -isSuspended, and it gets called before the first operation
gets enqueued on the replyQueue.
I can easily work around this by enqueuing a no-op operation on
replyQueue right after calling -setSuspended, but I'd like to know
whether there's a definitive answer to this question.
--Kyle Sluder
_______________________________________________
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