Latest 0.0.7
Homepage https://github.com/Luca9307/SCHRAsync
License MIT
Platforms ios 9.0, osx 10.10, tvos 9.0, watchos 2.0
Authors

SCHRAsync: Cool way to create Async Stream of Macro Steps
Swift 3.0
Platforms

Podspec
License

The purpose of SCHRAsync is to provide a simple way to layout a stream of macro-steps to be executed asynchronously and then run them. Maybe in one step you want to use library X to download all images from some url and in another you want to use library Y to Queue image processing.

Requirements

  • iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8.1+
  • Swift 3.0+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:


$ gem install cocoapods

To integrate SCHRAsync into your Xcode project using CocoaPods, specify it in your Podfile:

# source 'https://github.com/CocoaPods/Specs.git'
# use_frameworks!
# platform :ios, "8.0"

pod 'SCHRAsync'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate SCHRAsync into your Xcode project using Carthage, specify it in your Cartfile:

github "Luca9307/SCHRAsync"

Run carthage update to build the framework and drag the built SCHRAsync.framework into your Xcode project.

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but SCHRAsync does support its use on supported platforms.

Once you have your Swift package set up, adding SCHRAsync as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
.Package(url: "https://github.com/Luca9307/SCHRAsync.git")
]

Usage

Basic setup

Just create the steps and use SCHRAsync to run them:


let stepOne = SCHRStep { stepper, previousResult in
// previousResult in the first step is nil
// code to be executed on Step 1
stepper.next(result: stepOneResult)
}

let stepTwo = SCHRStep { stepper, previousResult in
// previousResult in the second step is the result of step 1
// The error can be anything as long as it conforms to the ErrorType protocol
// code to be executed on Step 2
stepper.abort(error: someError)
}

SCHRAsync(steps: stepOne,stepTwo).start()

In the step closure, don’t forget to finish the step either with some result or some error. Or else, the SCHRAsync will halt there.

Handle Closures

SCHRAsync provides closures you can use to be run when the flow starts, finishes, ends with error or is cancelled. All handle closures are run on the main thread.

Always

SCHRAsync(steps: stepOne,stepTwo).always { 
// code to be run when flow start.
}.start()
Finish

SCHRAsync(steps: stepOne,stepTwo).finish { finishState in
// code to be run after all steps finish
}.start()
Error

If you finish the step with error, the flow will end.


SCHRAsync(steps: stepOne,stepTwo).error { error in
// code to be executed if a step failed. The error will be sent here
}.onFinish { finishState in
// If one step is finished with error. This block will not be executed.
// Unless, no error closure is provided, in which case the SCHRAsync will 
// default to this closure with finishState = .Failed(let error)
}.start()
Cancel

If the flow is canceled.


let a = SCHRAsync(steps: stepOne,stepTwo).cancel{ 
// code to be executed if the flow is canceled.
}.finish{ finishState in
// If the flow is canceled. This block will not be executed.
// Unless, no cancel closure is provided, in which case the SCHRAsync will 
// default to this closure with finishState = .Canceled
}

a.start()
a.cancel()

Simple Syntax

You can use SCHRAsync, also in this cool way:


SCHRAsync().always {
//Initial code
}.then { stepper, result in
// previousResult in the first step is nil
// code to be executed on Step 1
  stepper.next(result)
}.then { stepper, result in
// previousResult in the second step is the result of step 1
// The error can be anything as long as it conforms to the ErrorType protocol
// code to be executed on Step 2
stepper.next(result)
}.finish { state in
// code to be run after all steps finish
}.start()

TODO

  • [ ] Travis CI
  • [ ] Unit Tests

Communication

  • If you find a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

License

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

Latest podspec

{
    "name": "SCHRAsync",
    "version": "0.0.7",
    "license": "MIT",
    "summary": "Cool way to create Async Stream of Macro Steps",
    "homepage": "https://github.com/Luca9307/SCHRAsync",
    "authors": {
        "Searchr": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Luca9307/SCHRAsync.git",
        "tag": "0.0.7"
    },
    "platforms": {
        "ios": "9.0",
        "osx": "10.10",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "source_files": "Source/*.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This