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
FutureProtocolyour implementation is currently using. - Publicly expose only the
FutureProtocolaspect of a deferred value, ensuring that only your implementation can fill the deferred value using thePromiseProtocolaspect.
-
Create a future whose
upon(_:execute:)methods forward tobase.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
workonqueue.Declaration
Swift
public static func async(upon queue: DispatchQueue = .any(), flags: DispatchWorkItemFlags = [], execute work: @escaping() -> Value) -> FutureParameters
queueA dispatch queue to perform the
workon.flagsOptions controlling how the
workis executed with respect to system resources.workA 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)
View on GitHub
Install in Dash
Future Structure Reference