Git Product home page Git Product logo

intelygenz / kommander-ios Goto Github PK

View Code? Open in Web Editor NEW
172.0 9.0 17.0 1.02 MB

A lightweight, pure-Swift library for manage the task execution in different threads. Through the definition a simple but powerful concept, Kommand.

Home Page: https://intelygenz.github.io/Kommander-iOS/

License: MIT License

Ruby 1.80% Swift 95.25% Objective-C 0.80% Shell 2.15%
kommander swift task execution thread kommand command pattern execute cancel success error main current operationqueue dispatchqueue dispatcher block closure concurrency

kommander-ios's Introduction

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.

kommander-ios's People

Contributors

alexruperez avatar igzcarlosmanzanas avatar igzrobertoestrada avatar juantrias avatar marhs avatar schneems avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kommander-ios's Issues

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.

Improve README.md

It is not clear which cases can be used Kommander or how it is used.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.