Kommander-Static 1.0

Kommander-Static 1.0

Jose Antonio García Yáñez 维护。



Kommander

Twitter Version License Platform Swift Carthage compatible Swift Package Manager Compatible Build Status Documentation Downloads Help Contribute to Open Source

Kommander 是一个 Swift 库,用于管理不同线程中的任务执行。通过定义一个简单但强大的概念 Kommand

灵感来自由 Wokdsem 提供的 Kommander Java 库。

Kommander

🌟特性

  • 制作 kommand 或多个 kommand
  • 执行 kommand 或多个 kommand
  • 取消 kommand 或多个 kommand
  • 重试 kommand 或多个 kommand
  • 设置 kommand 成功闭包
  • 设置 kommand 错误闭包
  • 主线程调度器
  • 当前线程调度器
  • 自定义 OperationQueue 调度器
  • 执行单个或多个 Operation
  • 执行顺序或并发闭包
  • 执行 DispatchWorkItem
  • Kommand 状态
  • iOS 兼容
  • watchOS 兼容
  • tvOS 兼容
  • macOS 兼容
  • Swift 4 版本
  • Swift 3 版本
  • Swift 2 版本
  • Objective-C 版本

📲安装

Kommander 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'Kommander'

为了与 Swift 3 兼容使用

pod 'Kommander', '~> 0.7'

为了与 Swift 2 兼容使用

pod 'Kommander', :git => 'https://github.com/intelygenz/Kommander-iOS.git', :tag => '0.3.0-swift2'

为了与 Objective-C 兼容使用

pod 'Kommander', :git => 'https://github.com/intelygenz/Kommander-iOS.git', :tag => '0.2.3-objc'

您还可以使用 Carthage 安装

github "intelygenz/Kommander-iOS"

您还可以使用 Swift 包管理器 安装

dependencies: [
    .package(url: "https://github.com/intelygenz/Kommander-iOS.git")
]

🐒使用方法

制作、执行、取消和重试 Kommands

Kommander().make {
    // Your code here
}.execute()
Kommander().make {
    // Your code here
}.execute(after: .seconds(2))
Kommander().make {
    return "Your string"
}.success { yourString in
    print(yourString)
}.execute()
Kommander().make {
    throw CocoaError(.featureUnsupported)
}.error { error in
    print(String(describing: error!))
}.execute()
取消后重试
let kommand = Kommander().make { () -> Any? in
    // Your code here
}.success { result in
    // Your success handling here
}.error { error in
    // Your error handling here
}.execute()

kommand.cancel()

kommand.retry()
失败后重试
let kommand = Kommander().make { () -> Any? in
    // Your code here
}.error { error in
    // Your error handling here
}.retry { error, executionCount in
    return executionCount < 2
}.execute()

创建 Kommanders

Kommander(deliverer: Dispatcher = .current, executor: Dispatcher = .default)

Kommander(deliverer: Dispatcher = .current, name: String, qos: QualityOfService = .default, maxConcurrentOperations: Int = .default)
快捷键
Kommander.main

Kommander.current

Kommander.default

Kommander.userInteractive

Kommander.userInitiated

Kommander.utility

Kommander.background

创建 Dispatchers

CurrentDispatcher()

MainDispatcher()

Dispatcher(name: String, qos: QualityOfService = .default, maxConcurrentOperations: Int = .default)
快捷键
Dispatcher.main

Dispatcher.current

Dispatcher.default

Dispatcher.userInteractive

Dispatcher.userInitiated

Dispatcher.utility

Dispatcher.background

❤️等等。

  • 非常欢迎贡献。
  • 归属感谢(让我们传播这些!),但不是强制性的。

👨‍💻作者

alexruperez[email protected]

juantrias[email protected]

RobertoEstrada[email protected]

👮‍♂️许可证

Kommander 适用于 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。