Skip to content

Instantly share code, notes, and snippets.

@NeoTeo
Created May 18, 2015 12:05
Show Gist options
  • Select an option

  • Save NeoTeo/ca062a80b645f13397d8 to your computer and use it in GitHub Desktop.

Select an option

Save NeoTeo/ca062a80b645f13397d8 to your computer and use it in GitHub Desktop.
Wait for async call using semaphores.
let sema = dispatch_semaphore_create(0)
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
// Do async stuff
// When finished, signal to continue below.
dispatch_semaphore_signal(sema)
}
// Wait for the load to complete.
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment