Skip to content

Instantly share code, notes, and snippets.

@coryhymel
Last active January 4, 2016 04:29
Show Gist options
  • Save coryhymel/8568929 to your computer and use it in GitHub Desktop.
Save coryhymel/8568929 to your computer and use it in GitHub Desktop.
Waiting for multiple GCD blocks to finish
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();
// Add a task to the group
dispatch_group_async(group, queue, ^{
// Some asynchronous work
});
// Do some other work while the tasks execute.
// When you cannot make any more forward progress,
// wait on the group to block the current thread.
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
// Release the group when it is no longer needed.
dispatch_release(group);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment