Docs
CodeRabbit
Cloudflare
Railway
AG Grid
WorkOS
Netlify
Clerk
OpenRouter
SerpAPI
Prisma
Sentry
Unkey
Electric
CodeRabbit
Cloudflare
Railway
AG Grid
WorkOS
Netlify
Clerk
OpenRouter
SerpAPI
Prisma
Sentry
Unkey
Electric
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher 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: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

Parameters

fn

() =>

options

<>

Returns

ts
(item): void;
(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

Returns

Example

ts
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