let eventLoop: EventLoop
The EventLoop
which is tied to the EventLoopFuture
and is used to notify all registered callbacks.
func always(@escaping (Result<Value, Error>) -> Void) -> EventLoopFuture<Value>
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has any result.
func and<OtherValue>(EventLoopFuture<OtherValue>) -> EventLoopFuture<(Value, OtherValue)>
Return a new EventLoopFuture
that succeeds when this “and” another provided EventLoopFuture
both succeed. It then provides the pair of results. If either one fails, the combined EventLoopFuture
will fail with the first error encountered.
func and<OtherValue>(value: OtherValue) -> EventLoopFuture<(Value, OtherValue)>
Return a new EventLoopFuture that contains this “and” another value. This is just syntactic sugar for future.and(loop.makeSucceedFuture(value))
.
func assertFailure(file: StaticString, line: UInt) -> EventLoopFuture<Value>
Attaches a callback to the EventLoopFuture
that asserts the original future’s failure.
func assertSuccess(file: StaticString, line: UInt) -> EventLoopFuture<Value>
Attaches a callback to the EventLoopFuture
that asserts the original future’s success.
func assumeIsolated() -> Isolated
Returns a variant of this EventLoopFuture
with less strict Sendable
requirements. Can only be called from on the EventLoop
to which this EventLoopFuture
is bound, will crash if that invariant fails to be met.
func assumeIsolatedUnsafeUnchecked() -> Isolated
Returns a variant of this EventLoopFuture
with less strict Sendable
requirements. Can only be called from on the EventLoop
to which this EventLoopFuture
is bound, will crash if that invariant fails to be met in debug builds.
func cascade(to: EventLoopPromise<Value>?)
Fulfills the given EventLoopPromise
with the results from this EventLoopFuture
.
func cascadeFailure<NewValue>(to: EventLoopPromise<NewValue>?)
Fails the given EventLoopPromise
with the error from this EventLoopFuture
if encountered.
func cascadeSuccess(to: EventLoopPromise<Value>?)
Fulfills the given EventLoopPromise
only when this EventLoopFuture
succeeds.
func flatMap<NewValue>(@escaping (Value) -> EventLoopFuture<NewValue>) -> EventLoopFuture<NewValue>
When the current EventLoopFuture<Value>
is fulfilled, run the provided callback, which will provide a new EventLoopFuture
.
func flatMapBlocking<NewValue>(onto: DispatchQueue, @escaping (Value) throws -> NewValue) -> EventLoopFuture<NewValue>
Chain an EventLoopFuture<NewValue>
providing the result of a IO / task that may block. For example:
func flatMapError(@escaping (Error) -> EventLoopFuture<Value>) -> EventLoopFuture<Value>
When the current EventLoopFuture<Value>
is in an error state, run the provided callback, which may recover from the error by returning an EventLoopFuture<NewValue>
. The callback is intended to potentially recover from the error by returning a new EventLoopFuture
that will eventually contain the recovered result.
func flatMapErrorThrowing(@escaping (Error) throws -> Value) -> EventLoopFuture<Value>
When the current EventLoopFuture<Value>
is in an error state, run the provided callback, which may recover from the error and returns a new value of type Value
. The provided callback may optionally throw
, in which case the EventLoopFuture
will be in a failed state with the new thrown error.
func flatMapErrorWithEventLoop(@escaping (Error, EventLoop) -> EventLoopFuture<Value>) -> EventLoopFuture<Value>
When the current EventLoopFuture<Value>
is in an error state, run the provided callback, which may recover from the error by returning an EventLoopFuture<NewValue>
. The callback is intended to potentially recover from the error by returning a new EventLoopFuture
that will eventually contain the recovered result.
func flatMapResult<NewValue, SomeError>(@escaping (Value) -> Result<NewValue, SomeError>) -> EventLoopFuture<NewValue>
When the current EventLoopFuture<Value>
is fulfilled, run the provided callback, which performs a synchronous computation and returns either a new value (of type NewValue
) or an error depending on the Result
returned by the closure.
func flatMapThrowing<NewValue>(@escaping (Value) throws -> NewValue) -> EventLoopFuture<NewValue>
When the current EventLoopFuture<Value>
is fulfilled, run the provided callback, which performs a synchronous computation and returns a new value of type NewValue
. The provided callback may optionally throw
.
func flatMapWithEventLoop<NewValue>(@escaping (Value, EventLoop) -> EventLoopFuture<NewValue>) -> EventLoopFuture<NewValue>
When the current EventLoopFuture<Value>
is fulfilled, run the provided callback, which will provide a new EventLoopFuture
alongside the EventLoop
associated with this future.
func fold<OtherValue>([EventLoopFuture<OtherValue>], with: @escaping (Value, OtherValue) -> EventLoopFuture<Value>) -> EventLoopFuture<Value>
Returns a new EventLoopFuture
that fires only when this EventLoopFuture
and all the provided futures
complete. It then provides the result of folding the value of this EventLoopFuture
with the values of all the provided futures
.
func foldWithEventLoop<OtherValue>([EventLoopFuture<OtherValue>], with: @escaping (Value, OtherValue, EventLoop) -> EventLoopFuture<Value>) -> EventLoopFuture<Value>
Returns a new EventLoopFuture
that fires only when this EventLoopFuture
and all the provided futures
complete. It then provides the result of folding the value of this EventLoopFuture
with the values of all the provided futures
.
func get() async throws -> Value
Get the value/error from an EventLoopFuture
in an async
context.
func hop(to: EventLoop) -> EventLoopFuture<Value>
Returns an EventLoopFuture
that fires when this future completes, but executes its callbacks on the target event loop instead of the original one.
func map<NewValue>(@escaping (Value) -> (NewValue)) -> EventLoopFuture<NewValue>
When the current EventLoopFuture<Value>
is fulfilled, run the provided callback, which performs a synchronous computation and returns a new value of type NewValue
.
func preconditionFailure(file: StaticString, line: UInt) -> EventLoopFuture<Value>
Attaches a callback to the EventLoopFuture
that preconditions the original future’s failure.
func preconditionSuccess(file: StaticString, line: UInt) -> EventLoopFuture<Value>
Attaches a callback to the EventLoopFuture
that preconditions the original future’s success.
func recover(@escaping (Error) -> Value) -> EventLoopFuture<Value>
When the current EventLoopFuture<Value>
is in an error state, run the provided callback, which can recover from the error and return a new value of type Value
. The provided callback may not throw
, so this function should be used when the error is always recoverable.
func unwrap<NewValue>(orElse: @escaping () -> NewValue) -> EventLoopFuture<NewValue>
Unwrap an EventLoopFuture
where its type parameter is an Optional
.
func unwrap<NewValue>(orError: Error) -> EventLoopFuture<NewValue>
Unwrap an EventLoopFuture
where its type parameter is an Optional
.
func unwrap<NewValue>(orReplace: NewValue) -> EventLoopFuture<NewValue>
Unwrap an EventLoopFuture
where its type parameter is an Optional
.
func wait(file: StaticString, line: UInt) throws -> Value
Wait for the resolution of this EventLoopFuture
by blocking the current thread until it resolves.
func whenComplete(@escaping (Result<Value, Error>) -> Void)
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has any result.
func whenCompleteBlocking(onto: DispatchQueue, @escaping (Result<Value, Error>) -> Void)
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has any result. The observer callback is permitted to block.
func whenFailure(@escaping (Error) -> Void)
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has a failure result.
func whenFailureBlocking(onto: DispatchQueue, @escaping (Error) -> Void)
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has a failure result. The observer callback is permitted to block.
func whenSuccess(@escaping (Value) -> Void)
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has a success result.
func whenSuccessBlocking(onto: DispatchQueue, @escaping (Value) -> Void)
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has a success result. The observer callback is permitted to block.