Swiftpack.co -  intelygenz/Kommander-iOS as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
intelygenz/Kommander-iOS
A lightweight, pure-Swift library for manage the task execution in different threads. Through the definition a simple but powerful concept, Kommand.
.package(url: "https://github.com/intelygenz/Kommander-iOS.git", from: "1.1")

Kommander

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

Kommander is a Swift library to manage the task execution in different threads. Through the definition a simple but powerful concept, Kommand.

Inspired on the Java library Kommander from Wokdsem.

Kommander

๐ŸŒŸ Features

  • โ˜‘ Make kommand or multiple kommands
  • โ˜‘ Execute kommand or multiple kommands
  • โ˜‘ Cancel kommand or multiple kommands
  • โ˜‘ Retry kommand or multiple kommands
  • โ˜‘ Set kommand success closure
  • โ˜‘ Set kommand error closure
  • โ˜‘ Set kommand error closure specifying Error type
  • โ˜‘ Main thread dispatcher
  • โ˜‘ Current thread dispatcher
  • โ˜‘ Custom OperationQueue dispatcher
  • โ˜‘ Execute single or multiple Operation
  • โ˜‘ Execute sequential or concurrent closures
  • โ˜‘ Execute DispatchWorkItem
  • โ˜‘ Kommand state
  • โ˜‘ iOS compatible
  • โ˜‘ watchOS compatible
  • โ˜‘ tvOS compatible
  • โ˜‘ macOS compatible
  • โ˜‘ Swift 4 version
  • โ˜‘ Swift 3 version
  • โ˜‘ Swift 2 version
  • โ˜‘ Objective-C version

๐Ÿ“ฒ Installation

Kommander is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Kommander'

For Swift 3 compatibility use:

pod 'Kommander', '~> 0.7'

For Swift 2 compatibility use:

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

For Objective-C compatibility use:

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

Or you can install it with Carthage:

github "intelygenz/Kommander-iOS"

Or install it with Swift Package Manager:

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

๐Ÿ’ Usage

Making, executing, cancelling and retrying 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()
Specify Error type:
Kommander().make {
    throw MyError.error
}.error(MyError.self) { error in
    // error is MyError type.
}.execute()
Retry after cancellation:
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()
Retry after failure:
let kommand = Kommander().make { () -> Any? in
    // Your code here
}.error { error in
    // Your error handling here
}.retry { error, executionCount in
    return executionCount < 2
}.execute()

Creating Kommanders:

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

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

Kommander.current

Kommander.default

Kommander.userInteractive

Kommander.userInitiated

Kommander.utility

Kommander.background

Creating Dispatchers:

CurrentDispatcher()

MainDispatcher()

Dispatcher(name: String, qos: QualityOfService = .default, maxConcurrentOperations: Int = .default)
Shortcuts:
Dispatcher.main

Dispatcher.current

Dispatcher.default

Dispatcher.userInteractive

Dispatcher.userInitiated

Dispatcher.utility

Dispatcher.background

โค๏ธ Etc.

  • Contributions are very welcome.
  • Attribution is appreciated (let's spread the word!), but not mandatory.

๐Ÿ‘จโ€๐Ÿ’ป Authors

alexruperez, alejandro.ruperez@intelygenz.com

juantrias, juan.trias@intelygenz.com

RobertoEstrada, roberto.estrada@intelygenz.com

๐Ÿ‘ฎโ€โ™‚๏ธ License

Kommander is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 170
Last commit: 2 years ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jackโ€™d and SCRUFF. We are two of the worldโ€™s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

Kommander 1.1
3 years ago
  • Set kommand error closure specifying Error type.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics