Skip to content

Instantly share code, notes, and snippets.

@sundeepgupta
Created May 9, 2017 22:42
Show Gist options
  • Save sundeepgupta/494e5a5ed3ed04fa7032b9671048182a to your computer and use it in GitHub Desktop.
Save sundeepgupta/494e5a5ed3ed04fa7032b9671048182a to your computer and use it in GitHub Desktop.
Async testing technique with semaphores based on http://stackoverflow.com/a/28285276/1672161
let semaphore = DispatchSemaphore(value: 0)
asyncFunction() { result in
XCTAssert(result)
semaphore.signal
}
while semaphore.wait(timeout: .now()) == .timedOut {
RunLoop.current.run(until: Date(timeIntervalSinceNow: 3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment