Created
April 4, 2016 12:58
-
-
Save ynechaev/5235ab0042d8cc508d176ca42c24528a to your computer and use it in GitHub Desktop.
GCD group dispatch and wait
This file contains 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(); | |
dispatch_group_enter(group); // pair 1 enter | |
[self computeInBackground:1 completion:^{ | |
NSLog(@"1 done"); | |
dispatch_group_leave(group); // pair 1 leave | |
}]; | |
dispatch_group_enter(group); // pair 2 enter | |
[self computeInBackground:2 completion:^{ | |
NSLog(@"2 done"); | |
dispatch_group_leave(group); // pair 2 leave | |
}]; | |
dispatch_group_notify(group, queue, ^{ | |
NSLog(@"All jobs are done"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment