The type of items in the stream
Maps a function over each item in the stream with controlled concurrency.
This is essentially mapBatch
with batchSize: 1
, meaning each item
is processed individually but with concurrency control.
The type of items returned by the mapping function
New stream with mapped items
Maps a function over batches of items in the stream with controlled concurrency.
Items are grouped into batches of the specified size, and batches are processed with the specified concurrency. This is ideal for bulk operations like database inserts, API calls with batch endpoints, or any operation that benefits from processing multiple items together.
The type of items returned by the mapping function
Async function to process each batch of items
Optional
config: BatchOptionConfiguration options for batching, concurrency, timeouts, and progress
New stream with items from processed batches
// Process items in batches
const results = await Stream([1, 2, 3, 4, 5, 6])
.mapBatch(async (batch) => {
// batch is [1, 2, 3] then [4, 5, 6]
console.log('Processing batch:', batch);
return batch.map(x => x * 2);
}, {
batchSize: 3,
concurrency: 2,
batchDelay: 1000 // Flush incomplete batches after 1s
});
Collects all items from the stream into an array.
Promise that resolves to an array containing all items from the stream
Stream is an abstraction over AsyncIterable that supports concurrent processing with batching.