ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - async-plus/async-plus: ⛓ A chainable interface for Swift's async/await.
⛓ A chainable interface for Swift's async/await. Contribute to async-plus/async-plus development by creating an account on GitHub.
Visit Site

GitHub - async-plus/async-plus: ⛓ A chainable interface for Swift's async/await.

GitHub - async-plus/async-plus: ⛓ A chainable interface for Swift's async/await.

async+

Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures. Have the best of both worlds: you can use the async solution built into the language, but keep all the useful features of promises.

✏️ Usage

Basic chaining operations are:

  • .then arranges blocks one after another, passing along any values
  • .recover recovers from a thrown error with a backup value (or block to run)
  • .catch catches any errors (and allows you to throw new ones for later catch blocks)
  • attempt { ... } kicks off a chain as in the example below:
attempt {
    return try await getThing()
}.recover {
    error in
    return try await backupGetThing(error)
}.then {
    thing in
    await thing.doYour()
}.catch {
    error in
    alert(error)
}

For comparison, if we tried to write the above flow without Async+ we'd get something like this:

Task.init {
    do {
        let thing: Thing
        do {
            thing = try await getThing()
        } catch {
            thing = try await backupGetThing(error)
        }
        await thing.doYour()
    } catch {
        error in
        alert(error)
    }
}

Async+ allows async and/or throwing code to remain unnested, modular, and concise. For a full list of operations see the documentation.

Want to still use chained code within a do/catch block, Task.init, or similar context? Easy: chains are fully interoperable with async and/or throwing contexts via the operations .async(), and .asyncThrows() at the end of the chain, for example:

let foo = await attempt{ ... }.then{ ... }.async() // non-throwing chain
let foo = try await attempt{ ... }.then{ ... }.asyncThrows() // throwing chain

If the chain doesn't throw you will not be able to call asyncThrows on it (it is a Guarantee<T> type rather than a Promise<T> type), and vice versa. Similarly, chains with potential for uncaught errors will raise an unused value warning at compilation time.

💾 Installation

Async+ can be installed with either SwiftPM or CocoaPods.

For SwiftPM, in Xcode go to <your project> -> <ProjectName> -> Package Dependencies -> "+" and enter: https://github.com/async-plus/async-plus.git

Or modify your Package.swift file:

dependencies: [
    .Package(url: "https://github.com/async-plus/async-plus.git", majorVersion: 1, minor: 1),
] 

For CocoaPods, in your Podfile:

target "Change Me!" do
  pod "AsyncPlus", "~> 1.1"
end

To use Async+ in a Swift file you must import AsyncPlus at the top of the file.

📘 Documentation

Getting Started

Operations

Using chains from async or throwing contexts

Motivation and common patterns

Cancellation

Migrating from PromiseKit

Frequently asked questions (FAQ)

🚀 Feedback and Contributing

This package is in its initial release: please provide feedback and suggestions in order to help shape the API, either by submitting an issue on Github or sending a message on Discord.

Special thanks to the developers of PromiseKit and mxcl for inspiring this work and promoting its development.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory