Last active
December 16, 2016 20:23
-
-
Save AsceticMonk/ead7128cf349ec93035250247396932d to your computer and use it in GitHub Desktop.
New Swift 3.0 Dispatch APIs
This file contains 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
import Foundation | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
// Do something on the main queue asynchronously | |
DispatchQueue.main.async { | |
print("Update UI") | |
} | |
// Do something after 2 seocnds | |
let someQueue = DispatchQueue(label: "some.example.queue") | |
let delayTime = DispatchTime.now() + .seconds(2) | |
someQueue.after(when: delayTime) { | |
print("Done") | |
} | |
// Perform a task concurrently for specified iterations | |
DispatchQueue.concurrentPerform(iterations: 3) { | |
print("\($0) time") | |
} | |
// Do something synchronously | |
someQueue.sync { | |
print("Blocking") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment