Iterator element type
Context type passed to callback
Promise that resolves when iteration is complete
function* logs() {
yield 'Starting...';
yield 'Processing...';
yield 'Complete!';
}
await processIterator(logs(), (msg) => console.log(msg));
// With context and chunked processing
const ctx = { count: 0 };
await processIterator(
largeDataIterator,
(item, ctx) => {
ctx.count++;
processItem(item);
},
{ ctx, chunkSize: 100 } // Yield every 100 items
);
console.log(`Processed ${ctx.count} items`);
Processes an iterator with a callback function for side effects.
Similar to consumeIterator but doesn't collect results - just processes each item sequentially. Supports chunked processing to avoid blocking the event loop during long-running iterations. Useful for side effects like logging, writing to files, or updating UI.