Look into dispatch_groups
, you can tie a dispatch_group
to a dispatch_queue
and be notified when all items in the group are finished using dispatch_group_wait
, even if you dispatch async to the queues.
Have a look at:
http://cocoasamurai.blogspot.com/2011/02/practical-design-patterns-with-blocks.html
To summarize:
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_async(group, queue, ^{
... do some stuff ...
});
dispatch_group_async(group, queue, ^{
... do some other stuff ...
});
// wait until those async functions are done
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
... continue doing stuff ...