Future

public struct Future<Value> : FutureProtocol

A type-erased wrapper over any future.

Forwards operations to an arbitrary underlying future having the same Value type, hiding the specifics of the underlying FutureProtocol.

This type may be used to:

  • Prevent clients from coupling to the specific kind of FutureProtocol your implementation is currently using.
  • Publicly expose only the FutureProtocol aspect of a deferred value, ensuring that only your implementation can fill the deferred value using the PromiseProtocol aspect.
  • Create a future whose upon(_:execute:) methods forward to base.

    Declaration

    Swift

    public init<Wrapped>(_ wrapped: Wrapped) where Value == Wrapped.Value, Wrapped : FutureProtocol
  • Wrap and forward future as if it were always filled with value.

    Declaration

    Swift

    public init(value: Value)
  • Create a future that will never get fulfilled.

    Declaration

    Swift

    public static var never: Future<Value> { get }
  • Create a future having the same underlying future as other.

    Declaration

    Swift

    public init(_ future: Future<Value>)
  • Declaration

    Swift

    public func upon(_ executor: Executor, execute body: @escaping(Value) -> Void)
  • Declaration

    Swift

    public func peek() -> Value?
  • Declaration

    Swift

    public func wait(until time: DispatchTime) -> Value?
  • Captures the value of asynchronously executing work on queue.

    Declaration

    Swift

    public static func async(upon queue: DispatchQueue = .any(), flags: DispatchWorkItemFlags = [], execute work: @escaping() -> Value) -> Future

    Parameters

    queue

    A dispatch queue to perform the work on.

    flags

    Options controlling how the work is executed with respect to system resources.

    work

    A function body that calculates and returns the fulfilled value for the future.

  • Declaration

    Swift

    public typealias Success = Value.Right
  • Create a future having the same underlying task as other.

    Declaration

    Swift

    public init<Wrapped>(resultFrom wrapped: Wrapped) where Wrapped : TaskProtocol, Value.Right == Wrapped.Success
  • Create a future having the same underlying task as other.

    Declaration

    Swift

    public init<Wrapped>(succeedsFrom wrapped: Wrapped) where Wrapped : FutureProtocol, Value.Right == Wrapped.Value
  • Creates an future having already filled successfully with value.

    Declaration

    Swift

    public init(success value: @autoclosure() throws -> Success)
  • Creates an future having already failed with error.

    Declaration

    Swift

    public init(failure error: Failure)