Framework
Version
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference

batch

Function: batch()

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

Defined in: batcher.ts:247

Creates a batcher that processes items in batches

Type Parameters

TValue

Parameters

fn

(items) => void

options

BatcherOptions<TValue>

Returns

Function

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

ts
const batchItems = batch<number>({
  batchSize: 3,
  processBatch: (items) => console.log('Processing:', items)
});

batchItems(1);
batchItems(2);
batchItems(3); // Triggers batch processing
const batchItems = batch<number>({
  batchSize: 3,
  processBatch: (items) => console.log('Processing:', items)
});

batchItems(1);
batchItems(2);
batchItems(3); // Triggers batch processing
Subscribe to Bytes

Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.

Bytes

No spam. Unsubscribe at any time.