Skip to content

Instantly share code, notes, and snippets.

@Pegolon
Created January 20, 2012 11:14
Show Gist options
  • Save Pegolon/1646742 to your computer and use it in GitHub Desktop.
Save Pegolon/1646742 to your computer and use it in GitHub Desktop.
Use a semaphore to block an asynchronous call
__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