Skip to main content
Version: SDK 5.0.x

Future

public struct Future<Value>

A future value of type Value.

Result

A result that can either succeed with Value or fail with Error.

public typealias Result = Swift.Result<Value, Error>

ObserveCallback

A callback type for observing the result.

public typealias ObserveCallback = (Result) -> Void

ObserveCallbackWithTimeout

A callback type for observing the result with a timeout consideration.

public typealias ObserveCallbackWithTimeout = (TimeoutResult<Value, Error>) -> Void

isFulfilled

A boolean property indicating whether the future has been fulfilled.

public var isFulfilled: Bool { get }

observe(...)

Observes the result of the future.

public func observe(
on queue: DispatchQueue? = nil,
using handler: @escaping ObserveCallback
)

Parameters

queueThe dispatch queue on which the handler is executed. If nil, an arbitrary queue is used.
handlerThe closure to call with the future’s result.

observeWithTimeout(...)

Observes the result of the future with a timeout.

public func observeWithTimeout(
on queue: DispatchQueue? = nil,
timeout: TimeInterval,
using handler: @escaping ObserveCallbackWithTimeout
)

Parameters

queueThe dispatch queue on which the callback is executed. If nil, an arbitrary queue is used.
timeoutThe time interval after which the future should timeout.
handlerThe closure to call with the future’s result or a timeout.

async()

Asynchronous

Asynchronously waits for the future to be resolved and returns the value.

Throws

An error if the future is resolved with a failure.

@available(iOS 13.0, *)
public func async() async throws -> Value

Return Value

The success value of the future.