Skip to content

Repository files navigation

Asynchronous

CI StatusVersionLicensePlatformDocumentationcodecov

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>{returnAsync{ resolve, reject inleturl=APIRouter.route(for:.users, id: id)letrequest=URLRequest(url: url)letsession=URLSession.shared
lettask= session.dataTask(with: request){ data, response, error iniflet error = error {reject(error) // You can also `throw error`!
}elseiflet data = data {do{letuser=tryJSONDecoder().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 iniflet 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 indisplay(error: error)}

Installation

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

pod'Asynchronous'

Available Subspecs

NameDescription
Asynchronous/AlamofireAlamofire support
Asynchronous/BrightFuturesBrightFutures support
Asynchronous/HydraAsyncHydraAsync support
Asynchronous/PromiseKitPromiseKit support
Asynchronous/PromisesPromises support
Asynchronous/Thenthen support

Contributing

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

Roadmap

  • ReactiveSwift support
  • RxSwift support
  • Tests
  • Better documentation
  • Improved README
  • Remove BrightFutures dependency
  • Carthage support
  • SwiftPM support
  • Fix unnecessary error type erasures
  • Fix tuple gate in Asyncify
  • Improve Example project

Author

Francesco Perrotti-Garcia, fpg1503@gmail.com

License

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

Releases

Packages

Contributors

Languages