RunKit 1.0.4

RunKit 1.0.4

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布上次发布2015年12月
SPM支持 SPM

Khoi.Geeky 维护。



RunKit 1.0.4

  • 作者:

  • Khoi

Grand Central Dispatch (GCD) 框架的 Swift 封装,支持方法链式调用。

您是否厌倦了这样做?

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")
    })
}

使用 RunKit

Run.background { 
    for index in 1...UInt64.max{
        print(index)
    }
}.main { 
    print("Back to main thread")
}

安装

用法

支持的队列

Run.main {}
Run.userInteractive {}
Run.userInitiated {}
Run.utility {}
Run.background {}

队列链式调用

Run.main { 
    print("main queue")
}.background { 
    print("background queue")
}.userInitiated {
    print("userInitiated queue")
}.main { 
    print("Back to main thread")
}

存储块引用以进行链式调用

let longRunningBlock = Run.background{
    for index in 1...UInt64.max{
        print(index)
    }
}
longRunningBlock.main{
    print("Back to main thread")
}

您还可以取消一个正在运行的过程

longRunningBlock.cancel()

或者等待其完成

longRunningBlock.wait()
print("Continue..")

许可证

RunKit 基于 MIT 许可证发布。有关详细信息,请参阅 LICENSE