Skip to content

Instantly share code, notes, and snippets.

@mxl
Last active October 19, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxl/dc501fd93074dda110ff to your computer and use it in GitHub Desktop.
Save mxl/dc501fd93074dda110ff to your computer and use it in GitHub Desktop.
import Foundation
func testFunction(completion: () -> ()) {
dispatch_async(dispatch_get_main_queue()) {
completion()
}
}
func testSemaphore() {
let semaphore = dispatch_semaphore_create(0)
testFunction {
dispatch_semaphore_signal(semaphore)
}
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
}
print("1")
testSemaphore()
print("2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment