TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2015 |
SPMSupports SPM | ✗ |
Maintained by Khoi.Geeky.
A Swift Wrapper for Grand Central Dispatch (GCD) Framework that supports method chaining.
Tired of this?
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)) { () -> Void in
for index in 1...UInt64.max{
print(index)
}
dispatch_async(dispatch_get_main_queue(), { () -> Void in
print("Back to main thread")
})
}
With Run
Run.background { () -> Void in
for index in 1...UInt64.max{
print(index)
}
}.main { () -> Void in
print("Back to main thread")
}
Supported Queues:
Run.main {}
Run.userInteractive {}
Run.userInitiated {}
Run.utility {}
Run.background {}
Queues Chaining:
Run.main { () -> Void in
print("main queue")
}.background { () -> Void in
print("background queue")
}.userInitiated { () -> Void in
print("userInitiated queue")
}.main { () -> Void in
print("Back to main thread")
}
Store blocks reference for chaining
let longRunningBlock = Run.background{
for index in 1...UInt64.max{
print(index)
}
}
longRunningBlock.main{
print("Back to main thread")
}
You can also cancel a running process
longRunningBlock.cancel()
Or wait for it to finish
longRunningBlock.wait()
print("Continue..")
Run is released under the MIT license. See LICENSE for details.