Asynchronously iterates over an array in batches.
Element type.
The array to iterate.
Items per batch (0 = entire array as one batch).
0
Async callback (batch, startIndex) => Promise<void>.
(batch, startIndex) => Promise<void>
If batch_size is negative or not a safe integer.
batch_size
Callbacks are awaited sequentially and receive shallow copies. A rejection stops iteration. With size 0, the callback runs once even for an empty array; with a positive size, empty arrays produce no callbacks.
await batchedForEach([1, 2, 3, 4, 5], 2, async (batch, i) => { console.log(i, batch); // 0 [1,2], 2 [3,4], 4 [5]}); Copy
await batchedForEach([1, 2, 3, 4, 5], 2, async (batch, i) => { console.log(i, batch); // 0 [1,2], 2 [3,4], 4 [5]});
Asynchronously iterates over an array in batches.