Classes

The following classes are available globally.

  • Use a future for doing work asynchronously and returning a result.

    A future can represent a value. Receivers of a Future can register callbacks that handle the value a future represents.

    func intensiveFunction() -> Future<String> {
       return Future {
           // Intensive computation
           return "Result"
       }
    }
    
    expensiveFunction().then { result in
       print("The result: \(result)")
    }
    

    If you want to wait until the future completes, you can use the !> prefix operator:

    let value = !>expensiveFunction()
    

    If you need error handling, use a ThrowingFuture.

    See more

    Declaration

    Swift

    public class Future<Wrapped>
  • A Future with support for error handling.

    expensiveComputation().then {
       print("result: \($0)")
    }.onError{
       print("error: \($0)")
    }
    

    The !> operator also throws when used with a ThrowingFuture.

    let result = try !>expensiveComputation()
    

    Not handling errors coming from a ThrowingFuture will result in an error.

    See more

    Declaration

    Swift

    public final class ThrowingFuture<Wrapped> : Future<Wrapped>
  • Produces Futures that can be completed with a value at a later time.

    See more

    Declaration

    Swift

    public class Completer<Wrapped>
  • Produces ThrowingFutures that can be completed with a value or error at a later time.

    See more

    Declaration

    Swift

    public class ThrowingCompleter<Wrapped>