Created
May 6, 2017 08:42
-
-
Save shoheiyokoyama/30506e2a98e041cc9d24fa1b7b160d63 to your computer and use it in GitHub Desktop.
DispatchWorkItem wait(timeout)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let queue = DispatchQueue(label: "queue", attributes: .concurrent) | |
let workItem = DispatchWorkItem { | |
sleep(3) | |
print("done") | |
} | |
queue.async(execute: workItem) | |
let time: DispatchTime = .now() + .seconds(1) | |
let result: DispatchTimeoutResult = workItem.wait(timeout: time) | |
print("after waiting: result is \(result)") //perform after 1 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment