Created
May 6, 2017 08:42
-
-
Save shoheiyokoyama/eea692935ec81f8bea4cf73a5a66ad3d 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