⚡ Asynchronous version of `Array.prototype.forEach`.
By default, it runs all iterations in parallel. You can limit the concurrency by providing a third argument.
Syntax
import { forEachAsync } from '@opentf/std';
forEachAsync<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.
Examples
const items = [1, 2, 3];
await forEachAsync(items, async (n) => {
console.log(n);
});