Skip to content

Instantly share code, notes, and snippets.

@berikv
Last active December 7, 2017 15:05
Show Gist options
  • Select an option

  • Save berikv/a4539e5295681a8eb005130f2a16c576 to your computer and use it in GitHub Desktop.

Select an option

Save berikv/a4539e5295681a8eb005130f2a16c576 to your computer and use it in GitHub Desktop.
Stop the current thread for a specified period using a semaphore
let deadlineTime = DispatchTime.now() + .seconds(100)
let semaphore = DispatchSemaphore(value: 1)
DispatchQueue.global().asyncAfter(deadline: deadlineTime) {
semaphore.signal()
}
semaphore.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment