Operator 是用 Swift 编写的对 Grand Central Dispatch 的包装。
Operator 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "Operator"
当在主线程上调用时,Operator 默认的上下文模型使用主队列,在其他任何地方调用时使用全局队列。Operator 支持与可用全局队列一致的上下文
通过传递枚举中的名称,Operator 支持创建串联和并发队列
Operator.async {
print("Execute asynchronously")
}
这相当于
Operator.async(.DefaultContextModel) {
print("Execute asynchronously")
}
要使用不同的上下文
Operator.async(.Background) {
print("Execute in the background")
}
Operator.delay(forSeconds: 10.0) {
print("Execute this 10 seconds later")
}
let customConcurrentContext = Context.Concurrent("com.myapp.mynewconcurrentqueue")
Operator.delay(forSeconds: 10.0, customConcurrentContext) {
print("Execute this 10 seconds later")
}
Operator.sync {
print("Execute this 10 seconds later")
}
Operator.sync(.High) {
print("Execute this 10 seconds later")
}
Operator.tick {
print("Execute this 10 seconds later")
}
Grant Oladipo
t: @kocodude
Operator 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。