Last active
January 4, 2016 04:29
-
-
Save coryhymel/8568929 to your computer and use it in GitHub Desktop.
Waiting for multiple GCD blocks to finish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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