The type of elements in the input array
The array of elements to iterate over.
The asynchronous callback function that will be executed for each element.
Optionaloptions: { concurrency?: number; continueOnError?: boolean } = {}Optional configuration
Optionalconcurrency?: numberMaximum number of concurrent operations
OptionalcontinueOnError?: booleanWhether to continue iterating when a callback throws
A Promise that resolves when all elements have been processed.
// Basic usage
await asyncForEach([1, 2, 3, 4], async (number) => {
await delay(500);
console.log(number);
});
Asynchronously iterates over an array, executing a provided
callbackfunction for each element. The function allows limiting the number of concurrently executed tasks, making it useful for managing concurrency in asynchronous operations (e.g., network requests, file operations).The function waits for all asynchronous operations to complete before resolving.