TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2015 |
SPMSupports SPM | ✗ |
Maintained by Francis Chong.
A lightweight GCD wrapper for Swift. Mostly copied from MacRuby’s Dispatch module.
To run the example project, clone the repo, and run pod install
from the Example directory first.
// Create a serial queue
let queue = Queue("Serial", .Serial)
// Create a concurrent queue
let queue = Queue("Concurrent", .Concurrent)
// It is serial by default
let queue = Queue("Concurrent")
// Get main queue
let queue = Queue.main()
// Get global queue via QOS
let queue = Queue.concurrent(.UserInteractive)
// Get global queue via priority
let queue = Queue.concurrent(priority: .Background)
// asynchronously
queue.async {
data = true
}
// synchronously
queue.sync {
data = true
}
queue.apply(10) {
// some concurrent task
}
queue.apply(0.3) {
// run after 0.3 seconds
}
Semaphore provides an efficient mechanism to synchronizes threads via a combination of waiting and signaling.
This is especially useful for controlling access to limited resources.
let queue = Queue("sample")
let semaphore = Semaphore(0)
queue.after(1.0) {
print "Hello"
semaphore.signal
}
semaphore.wait // -> true
To use this library in your project manually, just drag all swift files under Classes
to the project tree.
Francis Chong, [email protected]
Dispatch is available under the MIT license. See the LICENSE file for more info.