==(_:_:)
EventLoopFuture.swift:472static func == (lhs: EventLoopFuture<Value>, rhs: EventLoopFuture<Value>) -> Bool
static func == (lhs: EventLoopFuture<Value>, rhs: EventLoopFuture<Value>) -> Bool
import NIOCore
The core abstractions that make up SwiftNIO.
final class EventLoopFuture<Value>
Holder for a result that will be provided later.
@frozen struct Bool
A value type whose instances are either true
or false
.
static func andAllComplete(_ futures: [EventLoopFuture<Value>], on eventLoop: any EventLoop) -> EventLoopFuture<Void>
Returns a new EventLoopFuture
that succeeds when all of the provided EventLoopFuture
s complete.
static func andAllComplete(_ futures: [EventLoopFuture<Value>], promise: EventLoopPromise<Void>)
Completes a promise
when all of the provided EventLoopFuture
s have completed.
static func andAllSucceed(_ futures: [EventLoopFuture<Value>], on eventLoop: any EventLoop) -> EventLoopFuture<Void>
Returns a new EventLoopFuture
that succeeds only if all of the provided futures succeed.
static func andAllSucceed(_ futures: [EventLoopFuture<Value>], promise: EventLoopPromise<Void>)
Succeeds the promise if all of the provided futures succeed. If any of the provided futures fail then the promise
will be failed – even if some futures are yet to complete.
@preconcurrency static func reduce<InputValue>(_ initialResult: Value, _ futures: [EventLoopFuture<InputValue>], on eventLoop: any EventLoop, _ nextPartialResult: @escaping (Value, InputValue) -> Value) -> EventLoopFuture<Value> where Value : Sendable, InputValue : Sendable
Returns a new EventLoopFuture
that fires only when all the provided futures complete. The new EventLoopFuture
contains the result of reducing the initialResult
with the values of the [EventLoopFuture<NewValue>]
.
@preconcurrency static func reduce<InputValue>(into initialResult: Value, _ futures: [EventLoopFuture<InputValue>], on eventLoop: any EventLoop, _ updateAccumulatingResult: @escaping (inout Value, InputValue) -> Void) -> EventLoopFuture<Value> where Value : Sendable, InputValue : Sendable
Returns a new EventLoopFuture
that fires only when all the provided futures complete. The new EventLoopFuture
contains the result of combining the initialResult
with the values of the [EventLoopFuture<NewValue>]
. This function is analogous to the standard library’s reduce(into:)
, which does not make copies of the result type for each EventLoopFuture
.
@preconcurrency static func whenAllComplete(_ futures: [EventLoopFuture<Value>], on eventLoop: any EventLoop) -> EventLoopFuture<[Result<Value, any Error>]> where Value : Sendable
Returns a new EventLoopFuture
that succeeds when all of the provided EventLoopFuture
s complete. The new EventLoopFuture
will contain an array of results, maintaining ordering for each of the EventLoopFuture
s.
@preconcurrency static func whenAllComplete(_ futures: [EventLoopFuture<Value>], promise: EventLoopPromise<[Result<Value, any Error>]>) where Value : Sendable
Completes a promise
with the results of all provided EventLoopFuture
s.
@preconcurrency static func whenAllSucceed(_ futures: [EventLoopFuture<Value>], on eventLoop: any EventLoop) -> EventLoopFuture<[Value]> where Value : Sendable
Returns a new EventLoopFuture
that succeeds only if all of the provided futures succeed. The new EventLoopFuture
will contain all of the values fulfilled by the futures.
@preconcurrency static func whenAllSucceed(_ futures: [EventLoopFuture<Value>], promise: EventLoopPromise<[Value]>) where Value : Sendable
Completes the promise
with the values of all futures
if all provided futures succeed. If any of the provided futures fail then promise
will be failed.
let eventLoop: any EventLoop
The EventLoop
which is tied to the EventLoopFuture
and is used to notify all registered callbacks.
@preconcurrency func always(_ callback: @escaping (Result<Value, any Error>) -> Void) -> EventLoopFuture<Value>
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has any result.
@preconcurrency func and<OtherValue>(_ other: EventLoopFuture<OtherValue>) -> EventLoopFuture<(Value, OtherValue)> where OtherValue : Sendable
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.
@preconcurrency func and<OtherValue>(value: OtherValue) -> EventLoopFuture<(Value, OtherValue)> where OtherValue : Sendable
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 = #fileID, line: UInt = #line) -> EventLoopFuture<Value>
Attaches a callback to the EventLoopFuture
that asserts the original future’s failure.
func assertSuccess(file: StaticString = #fileID, line: UInt = #line) -> EventLoopFuture<Value>
Attaches a callback to the EventLoopFuture
that asserts the original future’s success.
func assumeIsolated() -> EventLoopFuture<Value>.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() -> EventLoopFuture<Value>.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.
@preconcurrency func cascade(to promise: EventLoopPromise<Value>?) where Value : Sendable
Fulfills the given EventLoopPromise
with the results from this EventLoopFuture
.
func cascadeFailure<NewValue>(to promise: EventLoopPromise<NewValue>?)
Fails the given EventLoopPromise
with the error from this EventLoopFuture
if encountered.
@preconcurrency func cascadeSuccess(to promise: EventLoopPromise<Value>?) where Value : Sendable
Fulfills the given EventLoopPromise
only when this EventLoopFuture
succeeds.
@preconcurrency func flatMap<NewValue>(_ callback: @escaping (Value) -> EventLoopFuture<NewValue>) -> EventLoopFuture<NewValue> where NewValue : Sendable
When the current EventLoopFuture<Value>
is fulfilled, run the provided callback, which will provide a new EventLoopFuture
.
@preconcurrency func flatMapBlocking<NewValue>(onto queue: DispatchQueue, _ callbackMayBlock: @escaping (Value) throws -> NewValue) -> EventLoopFuture<NewValue> where Value : Sendable, NewValue : Sendable
Chain an EventLoopFuture<NewValue>
providing the result of a IO / task that may block. For example:
@preconcurrency func flatMapError(_ callback: @escaping (any Error) -> EventLoopFuture<Value>) -> EventLoopFuture<Value> where Value : Sendable
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.
@preconcurrency func flatMapErrorThrowing(_ callback: @escaping (any 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.
@preconcurrency func flatMapErrorWithEventLoop(_ callback: @escaping (any Error, any EventLoop) -> EventLoopFuture<Value>) -> EventLoopFuture<Value> where Value : Sendable
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.
@preconcurrency func flatMapResult<NewValue, SomeError>(_ body: @escaping (Value) -> Result<NewValue, SomeError>) -> EventLoopFuture<NewValue> where SomeError : Error
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.
@preconcurrency func flatMapThrowing<NewValue>(_ callback: @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
.
@preconcurrency func flatMapWithEventLoop<NewValue>(_ callback: @escaping (Value, any EventLoop) -> EventLoopFuture<NewValue>) -> EventLoopFuture<NewValue> where NewValue : Sendable
When the current EventLoopFuture<Value>
is fulfilled, run the provided callback, which will provide a new EventLoopFuture
alongside the EventLoop
associated with this future.
@preconcurrency func fold<OtherValue>(_ futures: [EventLoopFuture<OtherValue>], with combiningFunction: @escaping (Value, OtherValue) -> EventLoopFuture<Value>) -> EventLoopFuture<Value> where Value : Sendable, OtherValue : Sendable
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
.
@preconcurrency func foldWithEventLoop<OtherValue>(_ futures: [EventLoopFuture<OtherValue>], with combiningFunction: @escaping (Value, OtherValue, any EventLoop) -> EventLoopFuture<Value>) -> EventLoopFuture<Value> where Value : Sendable, OtherValue : Sendable
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
.
@preconcurrency func get() async throws -> Value where Value : Sendable
Get the value/error from an EventLoopFuture
in an async
context.
@preconcurrency func hop(to target: any EventLoop) -> EventLoopFuture<Value> where Value : Sendable
Returns an EventLoopFuture
that fires when this future completes, but executes its callbacks on the target event loop instead of the original one.
@preconcurrency func map<NewValue>(_ callback: @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 = #fileID, line: UInt = #line) -> EventLoopFuture<Value>
Attaches a callback to the EventLoopFuture
that preconditions the original future’s failure.
func preconditionSuccess(file: StaticString = #fileID, line: UInt = #line) -> EventLoopFuture<Value>
Attaches a callback to the EventLoopFuture
that preconditions the original future’s success.
@preconcurrency func recover(_ callback: @escaping (any 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.
@preconcurrency func unwrap<NewValue>(orElse callback: @escaping () -> NewValue) -> EventLoopFuture<NewValue> where Value == NewValue?
Unwrap an EventLoopFuture
where its type parameter is an Optional
.
func unwrap<NewValue>(orError: any Error) -> EventLoopFuture<NewValue> where Value == NewValue?
Unwrap an EventLoopFuture
where its type parameter is an Optional
.
@preconcurrency func unwrap<NewValue>(orReplace replacement: NewValue) -> EventLoopFuture<NewValue> where Value == NewValue?, NewValue : Sendable
Unwrap an EventLoopFuture
where its type parameter is an Optional
.
@preconcurrency func wait(file: StaticString = #file, line: UInt = #line) throws -> Value where Value : Sendable
Wait for the resolution of this EventLoopFuture
by blocking the current thread until it resolves.
@preconcurrency func whenComplete(_ callback: @escaping (Result<Value, any Error>) -> Void)
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has any result.
@preconcurrency func whenCompleteBlocking(onto queue: DispatchQueue, _ callbackMayBlock: @escaping (Result<Value, any Error>) -> Void) where Value : Sendable
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has any result. The observer callback is permitted to block.
@preconcurrency func whenFailure(_ callback: @escaping (any Error) -> Void)
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has a failure result.
@preconcurrency func whenFailureBlocking(onto queue: DispatchQueue, _ callbackMayBlock: @escaping (any 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.
@preconcurrency func whenSuccess(_ callback: @escaping (Value) -> Void)
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has a success result.
@preconcurrency func whenSuccessBlocking(onto queue: DispatchQueue, _ callbackMayBlock: @escaping (Value) -> Void) where Value : Sendable
Adds an observer callback to this EventLoopFuture
that is called when the EventLoopFuture
has a success result. The observer callback is permitted to block.
struct Isolated
A struct wrapping an EventLoopFuture
that ensures all calls to any method on this struct are coming from the event loop of the future.
@preconcurrency func and<OtherValue>(_ other: EventLoopFuture<OtherValue>, file: StaticString = #fileID, line: UInt = #line) -> EventLoopFuture<(Value, OtherValue)> where OtherValue : Sendable
@preconcurrency func and<OtherValue>(value: OtherValue, file: StaticString = #fileID, line: UInt = #line) -> EventLoopFuture<(Value, OtherValue)> where OtherValue : Sendable
@preconcurrency func flatMap<NewValue>(file: StaticString = #fileID, line: UInt = #line, _ callback: @escaping (Value) -> EventLoopFuture<NewValue>) -> EventLoopFuture<NewValue> where NewValue : Sendable
func flatMapError(file: StaticString = #fileID, line: UInt = #line, _ callback: @escaping (any Error) -> EventLoopFuture<Value>) -> EventLoopFuture<Value> where Value : Sendable
func flatMapErrorThrowing(file: StaticString = #fileID, line: UInt = #line, _ callback: @escaping (any Error) throws -> Value) -> EventLoopFuture<Value>
@preconcurrency func flatMapResult<NewValue, SomeError>(file: StaticString = #fileID, line: UInt = #line, _ body: @escaping (Value) -> Result<NewValue, SomeError>) -> EventLoopFuture<NewValue> where SomeError : Error
@preconcurrency func flatMapThrowing<NewValue>(file: StaticString = #fileID, line: UInt = #line, _ callback: @escaping (Value) throws -> NewValue) -> EventLoopFuture<NewValue> where NewValue : Sendable
func map<NewValue>(file: StaticString = #fileID, line: UInt = #line, _ callback: @escaping (Value) -> NewValue) -> EventLoopFuture<NewValue>
@preconcurrency func recover(file: StaticString = #fileID, line: UInt = #line, _ callback: @escaping (any Error) -> Value) -> EventLoopFuture<Value>