On 5/10/12 1:42 PM, Dave wrote: > Hi, > > We are using a third party library that performs tasks asynchronously. > This is ok most of the time, but on some occasions I'd like to be able > to wait (not on the main thread) until an operation completes, > > The "doOperation: withCompletionBlock:" method just queues the operation > and returns. When the operation has finished, it calls the completion > block. > > I'd like to be able to be able to wait in the method that calls > doOperation: withCompletionBlock until the completion block is called, > something like this:
Am I correct in assuming that, given your terminology, you are using an NSOperationQueue? If so, and you have access to the code that's actually adding the operation to the NSOperationQueue, you could revise it to use -addOperations:waitUntilFinished: (passing YES as the second argument). You could of course write a wrapper around this (e.g. -doOperation:withCompletionBlock:waitUntilFinished:). If you are actually using dispatch queues, you could use dispatch_sync() to perform a blocking dispatch. Or are you stuck with the library code (perhaps already compiled) and are looking to do this entirely externally? If so, I see that Ken has already replied with a solution there. -- Conrad Shultz Synthetiq Solutions www.synthetiqsolutions.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com