Swiftpack.co -  tiny2n/Await as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Asynchronous Programming with async and await base protocol oriented programming
.package(url: "https://github.com/tiny2n/Await.git", from: "1.2.0")

Language Platform



Asynchronous Programming with async and await base protocol oriented programming
Await is a powerful Swift library

C# async and await https://msdn.microsoft.com/en-us//library/hh191443(v=vs.110).aspx


__Requires Swift 3 or later


Add the files to your project manually by dragging the Await directory into your Xcode project.



pod 'Await', :git => 'https://github.com/tiny2n/Await.git'


write this:

// async and await
async {
  let result = try await(AwaitExecute())    // AwaitCompletable Type

AwaitCompletable protocol this:

// AwaitCompletable
public protocol AwaitCompletable {
  associatedtype AwaitCompletableType

  var queue: DispatchQueue { get }
  var timeout: DispatchTimeInterval? { get }

  func execute(_ completion: @escaping (AwaitCompletableResult<AwaitCompletableType>) -> Void)

Custom this:

// Custom Await Completable
public struct AsyncObjectTask: AwaitCompletable {
  func execute(_ completion: @escaping (AwaitCompletableResult<AwaitCompletableType>) -> Void) {
    // execute task
    <#async code#>

    completion(.success(<#await completable type#>))
    // or completion(.failure(<#error#>))

example this:

// async block is Asynchronous
// await block is Synchronous

// serial call
async {
  do {
    let odd = try await(ACSum0To1000000000Odd())
    let even = try await(ACSum0To1000000000Even())
    let sum = try await(ACResultSum(odd, even))

    print(">>> odd: \(odd)")
    print(">>> even: \(even)")
    print(">>> sum: \(sum)")
  catch AwaitError.nil {
    print("throw nil")
  catch AwaitError.timeout {
    print("throw timeout")
  catch {
    print("thorw unknown")

// using subclassing by class AwaitConcurrentSupport<T>
// concurrent call
async {
  do {
    let result = try await(ACSum0To1000000000Even(), ACSum0To1000000000Odd())
    print(">>> count: \(result.count)")
    print(">>> even: \(result[1])")
    print(">>> odd: \(result[0])")
   catch {
    // Type: AwaitConcurrentError.concurrent<T>
    print("[Error] \(error)")


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


Stars: 24
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Supported SPM
3 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API