Skip to content

Instance Method

flatMapEach(on:_:)

Calls a closure, which returns an EventLoopFuture, on each element in a sequence that is wrapped by an EventLoopFuture. No results from each future are expected.
func flatMapEach(on eventLoop: any EventLoop, _ transform: @escaping (Value.Element) -> EventLoopFuture<Void>) -> EventLoopFuture<Void>

Parameters

eventLoop

The EventLoop to flatten the resulting array of futures on.

transform

The closure that each element in the sequence is passed into.

Return Value

A new EventLoopFuture that completes when all the returned EVentLoopFutures do.

Discussion

let users = eventLoop.future([User(name: "Tanner", ...), ...])
let saved = users.flatMapEach(on: eventLoop) { $0.save(on: database) }