Skip to content

Instantly share code, notes, and snippets.

@ynechaev
Created April 4, 2016 12:58
Show Gist options
  • Save ynechaev/5235ab0042d8cc508d176ca42c24528a to your computer and use it in GitHub Desktop.
Save ynechaev/5235ab0042d8cc508d176ca42c24528a to your computer and use it in GitHub Desktop.
GCD group dispatch and wait
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