fold(_:with:)

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.

EventLoopFuture.swift:1145
@preconcurrency func fold<OtherValue>(_ futures: [EventLoopFuture<OtherValue>], with combiningFunction: @escaping (Value, OtherValue) -> EventLoopFuture<Value>) -> EventLoopFuture<Value> where Value : Sendable, OtherValue : Sendable

Parameters

futures

An array of EventLoopFuture<NewValue> to wait for.

combiningFunction

A function that will be used to fold the values of two EventLoopFutures and return a new value wrapped in an EventLoopFuture.

Returns

A new EventLoopFuture with the folded value whose callbacks run on self.eventLoop.

This function is suited when you have APIs that already know how to return EventLoopFutures.

The returned EventLoopFuture will fail as soon as the a failure is encountered in any of the futures (or in this one). However, the failure will not occur until all preceding EventLoopFutures have completed. At the point the failure is encountered, all subsequent EventLoopFuture objects will no longer be waited for. This function therefore fails fast: once a failure is encountered, it will immediately fail the overall EventLoopFuture.