Forked from kaloprominat/xcode objective-c GCD dispatch group wait example
Created
December 6, 2022 15:50
-
-
Save sergenes/1c69e99b851c9e7043f532bc38eb5692 to your computer and use it in GitHub Desktop.
xcode objective-c GCD dispatch group wait example
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
//first | |
dispatch_async(queue, ^{ | |
dispatch_group_t group1 = dispatch_group_create(); | |
// Tasks goes here | |
for (NSInteger i = 0; i < 3; i++) { | |
dispatch_group_enter(group1); | |
someTaskWithCompletitionBlock:^() { | |
dispatch_group_leave(group1); | |
}; | |
} | |
dispatch_group_wait(group1, DISPATCH_TIME_FOREVER); | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// Perform completition block | |
}); | |
}); | |
//second | |
dispatch_group_t group2 = dispatch_group_create(); | |
for (NSInteger i = 0; i < 3; i++) { | |
dispatch_group_enter(group2); | |
someTaskWithCompletitionBlock:^() { | |
dispatch_group_leave(group2); | |
}; | |
} | |
dispatch_group_notify(group2, dispatch_get_main_queue(), ^{ | |
// Perform completition block | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment