Iterator element type
Callback return type
Promise resolving to array of all callback results
function* numbers() {
yield 1; yield 2; yield 3;
}
const results = await consumeIterator(numbers(), (n) => n * 2);
console.log(results); // [2, 4, 6]
// Async iterator with custom chunk size
const data = await consumeIterator(asyncIterator, processItem, {
chunkSize: 32 // Yield to event loop every 32 items
});
Consumes an iterator, applying a callback to each item and collecting results.
Processes sync or async iterators, calling the callback for each item and returning an array of all results. Supports chunked processing with configurable chunk size to yield control back to the event loop periodically.