Instance Method
future(result:)
Creates a new
Future from the worker’s event loop, succeeded or failed based on the input Result.func future<T>(result: Result<T, any Error>) -> EventLoopFuture<T>
Parameters
resultThe result that the future will wrap.
Return Value
The succeeded or failed future.
Discussion
let a: EventLoopFuture<String> = req.future(.success("hello"))
let b: EventLoopFuture<String> = req.future(.failed(Abort(.imATeapot))
See Also
EventLoop and EventLoopGroup
flatten(_:)Returns a newEventLoopFuturethat succeeds only when all the provided futures succeed. The newEventLoopFuturecontains an array of results, maintaining same ordering as the futures.flatten(_:)Returns a newEventLoopFuturethat succeeds only when all the provided futures succeed, ignoring the resolved values.future()Creates a new, succeededEventLoopFuturefrom the worker’s event loop with aVoidvalue.future(error:)Creates a new, failedEventLoopFuturefrom the worker’s event loop.future(_:)Creates a new, succeededEventLoopFuturefrom the worker’s event loop.tryFuture(_:)An alternate name for this would befuture(catching:), but with that name, trailing closure syntax just looks likeel.future { ... }, which does not indicate to readers of the code that it is the error-capturing version. Since such an indication is highly desirable, a slightly less idiomatic name is used instead.