Skip to main content

batch

function batch<TValue>(fn, options): (item) => void;

Defined in: batcher.ts:323

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.

Type Parameters

TValue

TValue

Parameters

fn

(items) => void

options

BatcherOptions<TValue>

Returns

(item): void;

Adds an item to the batcher If the batch size is reached, timeout occurs, or shouldProcess returns true, the batch will be processed

Parameters

item

TValue

Returns

void

Example

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