Kommander is a Swift library to manage the task execution in different threads.

Overview

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, [email protected]

juantrias, [email protected]

RobertoEstrada, [email protected]

👮‍♂️ License

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

Comments
  • This closes #5 implementing retry policy.

    This closes #5 implementing retry policy.

    Issue Link 🔗

    https://github.com/intelygenz/Kommander-iOS/issues/5

    Goals ⚽

    Close https://github.com/intelygenz/Kommander-iOS/issues/5 implementing retry policy.

    Implementation Details 🚧

    Retry closure with error and execution count params called on executor when the Kommand fails.

    Note: You can "suspend" (for example sleep) the retry closure to implement timed retries, because it's executed using the executor.


    This change is Reviewable

    enhancement help wanted question 
    opened by alexruperez 6
  • Throw KommandCancelledError (RecoverableError) when we cancel a Kommand

    Throw KommandCancelledError (RecoverableError) when we cancel a Kommand

    Issue Link :https://github.com/intelygenz/Kommander-iOS/issues/6:

    Goals :soccer:

    Let the user Retry an operation previously cancelled

    Implementation Details :construction:

    • Add new method to retry() a Kommand
    • Return KommandCancelledError instead of CocoaError when a Kommand is cancelled

    Testing Details :mag:

    • test_nCalls_andCancel_andRetry
    • test_nCalls_andCancel_andRetryFromError

    This change is Reviewable

    opened by juantrias 5
  • Add Retry Kommand capability.

    Add Retry Kommand capability.

    Just as we can cancel a Kommand, we want add the capability to retry them after failure.

    We have to think about how it would work, a good starting point could be our NetClient retry policy.

    enhancement 
    opened by alexruperez 4
  • This will resolve #7 deprecating

    This will resolve #7 deprecating

    ... some DispatchQueue methods and initializers.

    Issue Link 🔗

    Too many custom initializers with too many parameters.

    Implementation Details :construction:

    • [x] Deprecates some DispatchQueue methods and initializers.

    This change is Reviewable

    enhancement help wanted question hacktoberfest 
    opened by alexruperez 1
  • [ci skip] Get more Open Source Helpers

    [ci skip] Get more Open Source Helpers

    CodeTriage is an app I have maintained for the past 4-5 years with the goal of getting people involved in Open Source projects like this one. The app sends subscribers a random open issue for them to help "triage". For some languages you can also suggested areas to add documentation.

    The initial approach was inspired by seeing the work of the small core team spending countless hours asking "what version was this in" and "can you give us an example app". The idea is to outsource these small interactions to a huge team of volunteers and let the core team focus on their work.

    I want to add a badge to the README of this project. The idea is to provide an easy link for people to get started contributing to this project. A badge indicates the number of people currently subscribed to help the repo. The color is based off of open issues in the project.

    Here are some examples of other projects that have a badge in their README:

    • https://github.com/crystal-lang/crystal
    • https://github.com/rails/rails
    • https://github.com/codetriage/codetriage

    Thanks for building open source software, I would love to help you find some helpers.


    This change is Reviewable

    help wanted question 
    opened by schneems 0
  • Too many custom initializers with too many parameters.

    Too many custom initializers with too many parameters.

    Keeping the number of parameters low makes units easier to understand and reuse. Limit the number of parameters per unit to at most 4. Alternatively, try extracting parts of units that require fewer parameters.

    enhancement hacktoberfest 
    opened by alexruperez 0
  • Add Undo Kommand capability.

    Add Undo Kommand capability.

    Just as we can cancel a Kommand, we want add the capability to undo them.

    We have to think about how it would work, a good starting point could be save input and result in the Kommand object using Memento pattern.

    Thanks @Sefford for inspiring this issue.

    enhancement wontfix 
    opened by alexruperez 0
Releases(1.1)
Owner
Intelygenz
In Code We Trust - We deliver groundbreaking software solutions and applied AI that propel business growth.
Intelygenz
Queues, timers, and task groups in Swift

Dispatcher eases the pain of using Grand Central Dispatch by introducing 4 new Swift classes. Dispatcher Queue Group Timer Requirements Swift 2.0+ Ins

Alec Larson 109 Jan 29, 2022
⚡️ Fast async task based Swift framework with focus on type safety, concurrency and multi threading

Our apps constantly do work. The faster you react to user input and produce an output, the more likely is that the user will continue to use your appl

Said Sikira 814 Oct 30, 2022
A Task Queue Class developed in Swift (by Marin Todorov)

TaskQueue Table of Contents Intro Installation CocoaPods Carthage Simple Examples Synchronous tasks Asynchronous tasks Serial and Concurrent Tasks GCD

Marin Todorov 677 Jan 3, 2023
Several synchronization primitives and task synchronization mechanisms introduced to aid in modern swift concurrency.

AsyncObjects Several synchronization primitives and task synchronization mechanisms introduced to aid in modern swift concurrency. Overview While Swif

SwiftyLab 20 Jan 3, 2023
AsyncTaskKit - contains some additions to async/await Task

AsyncTaskKit This repo contains some additions to async/await Task. In general i

Michał Zaborowski 0 Jan 2, 2022
Hydra ⚡️ Lightweight full-featured Promises, Async & Await Library in Swift

Lightweight full-featured Promises, Async & Await Library in Swift What's this? Hydra is full-featured lightweight library which allows you to write b

Daniele Margutti 2k Dec 24, 2022
AwaitKit is a powerful Swift library which provides a powerful way to write asynchronous code in a sequential manner.

AwaitKit is a powerful Swift library inspired by the Async/Await specification in ES8 (ECMAScript 2017) which provides a powerful way to write asynchronous code in a sequential manner.

Yannick Loriot 752 Dec 5, 2022
AutoLogout is a swift library for managing user's session on inactivity.

On user inactivity, it will show an alert box to continue session or Logout as shown in screen shot, according to time set.

Adnan Yousaf 9 Jul 7, 2022
An actor model library for swift.

Aojet Aojet is an actor model implemetion for swift. Features Asynchronous, non-blocking and highly performant message-driven programming model Safe a

null 37 Apr 7, 2022
Hydra: Lightweight full-featured Promises, Async-Await Library in Swift

Async Functions for ECMAScript The introduction of Promises and Generators in EC

Ecma TC39 1.6k Oct 17, 2022
A declarative state management and dependency injection library for SwiftUI x Concurrency

A declarative state management and dependency injection library for SwiftUI x Concurrency

Ryo Aoyama 199 Jan 1, 2023
Lightweight async/await networking library with interceptor support - usable from iOS 13+.

Lightweight async/await networking library with interceptor support. ?? Getting started AsyncNetwork's session acts as a wrapper to URLSession by addi

Paul 9 Oct 4, 2022
A complete set of primitives for concurrency and reactive programming on Swift

A complete set of primitives for concurrency and reactive programming on Swift 1.4.0 is the latest and greatest, but only for Swift 4.2 and 5.0 use 1.

AsyncNinja 156 Aug 31, 2022
Futures is a cross-platform framework for simplifying asynchronous programming, written in Swift.

Futures Futures is a cross-platform framework for simplifying asynchronous programming, written in Swift. It's lightweight, fast, and easy to understa

David Ask 60 Aug 11, 2022
GroupWork is an easy to use Swift framework that helps you orchestrate your concurrent, asynchronous functions in a clean and organized way

GroupWork is an easy to use Swift framework that helps you orchestrate your concurrent, asynchronous functions in a clean and organized way. This help

Quan Vo 42 Oct 5, 2022
SwiftCoroutine - Swift coroutines for iOS, macOS and Linux.

Many languages, such as Kotlin, Go, JavaScript, Python, Rust, C#, C++ and others, already have coroutines support that makes the async/await pattern i

Alex Belozierov 808 Dec 1, 2022
Venice - Coroutines, structured concurrency and CSP for Swift on macOS and Linux.

Venice provides structured concurrency and CSP for Swift. Features Coroutines Coroutine cancelation Coroutine groups Channels Receive-only chan

Zewo 1.5k Dec 22, 2022
Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch

Async Now more than syntactic sugar for asynchronous dispatches in Grand Central Dispatch (GCD) in Swift Async sugar looks like this: Async.userInitia

Tobias Due Munk 4.6k Dec 27, 2022
Elegant ⏱ interface for Swift apps

Each Elegant ⏱ interface for Swift apps Each is a NSTimer bridge library written in Swift. Features Requirements Installation Usage Leaks License Feat

Luca D'Alberti 764 Dec 29, 2022