Functions

The following functions are available globally.

  • Shorthand for creating a new Future<T>.

    Note that the callback provided to this method will execute on the provided dispatch queue.

    Declaration

    Swift

    public func promise<T>(on queue: DispatchQueue = .futures, _ body: @escaping () throws -> T) -> Future<T>

    Parameters

    queue

    Dispatch queue to execute the callback on.

    body

    Function that returns a value, assigned to the future returned by this function.

    Return Value

    A future that will receive the eventual value.

  • Shorthand for creating a new Future<T>, in an asynchronous fashion.

    Note that the callback provided to this method will execute on the provided dispatch queue.

    Declaration

    Swift

    public func promise<T>(
        _ type: T.Type,
        on queue: DispatchQueue = .futures,
        _ body: @escaping (@escaping (_ value: FutureResult<T>) -> Void) throws -> Void) -> Future<T>

    Parameters

    type

    Type of the future value.

    queue

    Dispatch queue to execute the callback on.

    body

    A function with a completion function as its parameter, taking a FutureResult<T>, which will be used to resolve the future returned by this method.

    value

    FutureResult<T> to resolve the future with.

    Return Value

    A future that will receive the eventual value.