Skip to content

Instantly share code, notes, and snippets.

@reddavis
Last active January 3, 2016 07:59
Show Gist options
  • Save reddavis/8433096 to your computer and use it in GitHub Desktop.
Save reddavis/8433096 to your computer and use it in GitHub Desktop.
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, dispatch_get_main_queue(), ^{
double delayInSeconds = 2.0;
dispatch_time_t firstTaskPopTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(firstTaskPopTime, dispatch_get_main_queue(), ^(void) {
NSLog(@"Task 1 complete");
});
});
dispatch_group_async(group, dispatch_get_main_queue(), ^{
double delayInSeconds = 1.0;
dispatch_time_t secondTaskPopTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(secondTaskPopTime, dispatch_get_main_queue(), ^(void) {
NSLog(@"Task 2 complete");
});
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
NSLog(@"All tasks complete");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment