⚡ Asynchronous version of `Array.prototype.forEach`.
Info
By default, it runs all iterations in parallel. You can limit the concurrency by providing a third argument.
Syntax
TypeScript
import { eachAsync } from '@opentf/std'; eachAsync<T>( arr: T[], cb: (value: T, index: number) => Promise<void>, concurrency?: number ): Promise<void>;
Parameters
arr: The array to iterate over.cb: An async callback function for each element.concurrency(Optional): The maximum number of concurrent executions. Default:Infinity.
Returns
A Promise that resolves when all iterations are complete.
Sparse array holes are skipped, matching native Array.prototype.forEach() behavior.
Examples
TypeScript
const items = [1, 2, 3]; await eachAsync(items, async (n) => { console.log(n); });