Skip to content

Instantly share code, notes, and snippets.

@shoheiyokoyama
Created May 6, 2017 08:18
Show Gist options
  • Save shoheiyokoyama/d83ac796635d0ada73e53717d97422d7 to your computer and use it in GitHub Desktop.
Save shoheiyokoyama/d83ac796635d0ada73e53717d97422d7 to your computer and use it in GitHub Desktop.
DispatchWorkItem wait()
let queue = DispatchQueue(label: "queue", attributes: .concurrent)
let workItem = DispatchWorkItem {
sleep(3)
print("done")
}
queue.async(execute: workItem)
print("before waiting")
workItem.wait()
print("after waiting")
//before waiting
//done
//after waiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment