Waiting until two async blocks are executed (Version #2)

This is a nice variant to this other post. It gives you… way too much flexibility!

[cc lang=”objc”]
dispatch_group_t group = dispatch_group_create();

dispatch_group_enter(group);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
NSLog(@”Block1″);
[NSThread sleepForTimeInterval:5.0];
dispatch_group_leave(group);
NSLog(@”Block1 End”);
});

dispatch_group_enter(group);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
NSLog(@”Block2″);
[NSThread sleepForTimeInterval:8.0];
dispatch_group_leave(group);
NSLog(@”Block2 End”);
});

dispatch_group_notify(group, dispatch_get_main_queue(), ^ {
NSLog(@”Group Notify Block3 :: %d”, [NSThread isMainThread]);
});
[/cc]

%d