Latest 0.1.0
Homepage https://github.com/fpg1503/Asynchronous
License MIT
Platforms ios 9.0
Authors

CI Status
Version
License
Platform
Documentation
codecov

Asynchronous is a one-stop shop for your async needs, the user can use the subspecs to automatically run the Async code using completion handlers, BrightFutures, HydraAsync, PromiseKit, Promises, then and much more!

The ultimate answer to which asynchronous abstraction should I use in my API?, just use Asynchronous and give your users freedom without the headache of adding several dependencies and different abstractions to your code!

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Sample use case

Let’s say you’re writing a mobile SDK that does asynchronous tasks (such as HTTP requests), just like the following:

func getUser(by id: String) -> Async<User> {
    return Async { resolve, reject in
        let url = APIRouter.route(for: .users, id: id)
        let request = URLRequest(url: url)

        let session = URLSession.shared
        let task = session.dataTask(with: request) { data, response, error in
            if let error = error {
                reject(error) // You can also `throw error`!
            } else if let data = data {
                do {
                    let user = try JSONDecoder().decode(User.self, from: data)
                    resolve(user)
                } catch (let error) {
                    reject(error)
                }
            } else {
                reject(NSError(domain: "my.domain", code: 123))
            }
        }
        task.resume()
    }
}

That’s it! You simply create an Async and call resolve or reject once your task is finished.

The user can either add a completion block or use their favorite asynchronous abstraction:

Completion

apiClient.getUser(by: id).async { user, error in
    if let user = value {
        userName.text = user.name
    } else {
        display(error: error)
    }
}

Promise

apiClient.getUser(by: id).promise()
.then { user in
    userName.text = user.name
}.catch { error in
    display(error: error)
}

Installation

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

pod 'Asynchronous'

Available Subspecs

Name Description
Asynchronous/Alamofire Alamofire support
Asynchronous/BrightFutures BrightFutures support
Asynchronous/HydraAsync HydraAsync support
Asynchronous/PromiseKit PromiseKit support
Asynchronous/Promises Promises support
Asynchronous/Then then support

Contributing

Contributions are encourajed and appreciated!
For more information take a look at CONTRIBUTING.md.

Roadmap

  • [ ] ReactiveSwift support
  • [ ] RxSwift support
  • [x] Tests
  • [x] Better documentation
  • [ ] Improved README
  • [x] Remove BrightFutures dependency
  • [ ] Carthage support
  • [ ] SwiftPM support
  • [x] Fix unnecessary error type erasures
  • [ ] Improve Example project

Author

Francesco Perrotti-Garcia, [email protected]

License

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

Latest podspec

{
    "name": "Asynchronous",
    "version": "0.1.0",
    "summary": "Implementation agnostic asynchronous code",
    "default_subspecs": "Core",
    "description": "Async is a one-stop shop for your async needs, the user can use the subspecsnto automatically run the Async code using completion handlers, BrightFutures, nHydraAsync, PromiseKit, Promises, then and much more!",
    "homepage": "https://github.com/fpg1503/Asynchronous",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "fpg1503": "[email protected]"
    },
    "source": {
        "git": "https://github.com/fpg1503/Asynchronous.git",
        "tag": "0.1.0"
    },
    "social_media_url": "https://twitter.com/fpg1503",
    "platforms": {
        "ios": "9.0"
    },
    "subspecs": [
        {
            "name": "Core",
            "dependencies": {
                "Result": []
            },
            "source_files": "Asynchronous/Core/*.swift"
        },
        {
            "name": "BrightFutures",
            "dependencies": {
                "BrightFutures": []
            },
            "source_files": "Asynchronous/Extensions/Async+BrightFutures.swift"
        },
        {
            "name": "PromiseKit",
            "dependencies": {
                "PromiseKit": []
            },
            "source_files": "Asynchronous/Extensions/Async+PromiseKit.swift"
        },
        {
            "name": "Promises",
            "dependencies": {
                "Promises": []
            },
            "source_files": "Asynchronous/Extensions/Async+Promises.swift"
        },
        {
            "name": "HydraAsync",
            "dependencies": {
                "HydraAsync": []
            },
            "source_files": "Asynchronous/Extensions/Async+HydraAsync.swift"
        },
        {
            "name": "Then",
            "dependencies": {
                "thenPromise": []
            },
            "source_files": "Asynchronous/Extensions/Async+Then.swift"
        },
        {
            "name": "Alamofire",
            "dependencies": {
                "Alamofire": []
            },
            "source_files": "Asynchronous/Extensions/Alamofire+Async.swift"
        }
    ]
}

Pin It on Pinterest

Share This