Created
January 20, 2012 11:14
-
-
Save Pegolon/1646742 to your computer and use it in GitHub Desktop.
Use a semaphore to block an asynchronous call
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
__block dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | |
[self callAsyncBlock:^() { | |
// Do some work | |
dispatch_semaphore_signal(semaphore); | |
}]; | |
// Wait until the semaphore has been signaled | |
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | |
dispatch_release(semaphore); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment