function batch<TValue>(fn, options): (item) => void
function batch<TValue>(fn, options): (item) => void
Defined in: batcher.ts:322
Creates a batcher that processes items in batches.
This synchronous version is lighter weight and often all you need - upgrade to asyncBatch when you need promises, retry support, abort/cancel capabilities, or advanced error handling.
• TValue
(items) => void
BatcherOptions<TValue>
Function
Adds an item to the batcher If the batch size is reached, timeout occurs, or shouldProcess returns true, the batch will be processed
TValue
void
const batchItems = batch<number>(
(items) => console.log('Processing:', items),
{
maxSize: 3,
onExecute: (batch, batcher) => console.log('Batch executed:', batch)
}
);
batchItems(1);
batchItems(2);
batchItems(3); // Triggers batch processing
const batchItems = batch<number>(
(items) => console.log('Processing:', items),
{
maxSize: 3,
onExecute: (batch, batcher) => console.log('Batch executed:', batch)
}
);
batchItems(1);
batchItems(2);
batchItems(3); // Triggers batch processing
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.
