Kommander-iOS
  • March 15, 2024

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.

🌟 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

GitHub


View Github

#block #cancel #closure #command #concurrency #current #dispatcher #dispatchqueue #error #execute #execution #kommand #kommander #main #operationqueue #pattern #success #swift #task #thread
YOU MIGHT ALSO LIKE...
CameraBackground

Features Both front and back camera supported. Flash modes: auto, on, off. Countdown timer. Tap to focus. Pinch to zoom. Usage  

DKCamera

Description A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so ...

HorizonSDK-iOS

Horizon SDK is a state of the art real-time video recording / photo shooting iOS library. Some of the features ...

LLSimpleCamera

LLSimpleCamera: A simple customizable camera - video recorder control LLSimpleCamera is a library for creating a customized camera - video ...

RSBarcodes_Swift

RSBarcodes allows you to read 1D and 2D barcodes using the metadata scanning capabilities introduced with iOS 7 and generate ...