Swift Package Index


An alternative of `async/await` in Swift


  • The latest stable release is 0.2.0. Released 2 years ago.
  • The latest beta release is 0.3.0-alpha. Released 2 years ago.
  • The last commit to master was 2 years ago.

Swift Version Compatibility

  • 0.2.0, 0.3.0-alpha, and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 0.2.0, 0.3.0-alpha, and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

AsyncK

Carthage compatible Swift Package Manager

AsyncK provides Async, await, beginAsync and suspendAsync which are compatible with ones in this proposal.

The following code written with async/await

func foo() async -> Int {
    return suspendAsync { continuation in
        // ...
    }
}

func bar(_ x: Int) async -> Int {
    // ...
}

beginAsync {
    let a = await foo()
    let b = await bar(a)
    print(b)
}

can be rewritten as follows:

func foo() -> Async<Int> {
    return suspendAsync { continuation in
        // ...
    }
}

func bar(_ x: Int) -> Async<Int> {
    // ...
}

beginAsync {
    foo().await { a in
        bar(a).await { b -> Void in
            print(b)
        }
    }
}

It is also possible to flatten the nest inside the beginAsync's trailing closure.

foo().await { a in
    bar(a)
}.await { b -> Void in
    print(b)
}

License

MIT