File: asyncBatch.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
React
Version
Latest
Search...
+ K
Menu
Getting Started
Guides
API Reference
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Debouncer Examples
Throttler Examples
Rate Limiter Examples
Queue Examples
Batcher Examples
TanStack Query Examples
Framework
React
Version
Latest
Menu
Getting Started
Guides
API Reference
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Debouncer Examples
Throttler Examples
Rate Limiter Examples
Queue Examples
Batcher Examples
TanStack Query Examples
On this page
Copy Markdown
Function: asyncBatch()
======================
ts
function asyncBatch<TValue>(fn, options): (item) => Promise<any>;
function asyncBatch<TValue>(fn, options): (item) => Promise<any>;
Defined in: async-batcher.ts:582
Creates an async batcher that processes items in batches.
Async vs Sync Versions: The async version provides advanced features over the sync batch function:
The sync batch function is lighter weight and simpler when you don't need async features, return values, or execution control.
What is Batching? Batching is a technique for grouping multiple operations together to be processed as a single unit.
Configuration Options:
Error Handling:
State Management:
Type Parameters
---------------
### TValue
TValue
(items) => Promise<any>
AsyncBatcherOptions <TValue>
ts
(item): Promise<any>;
(item): Promise<any>;
Adds an item to the async batcher If the batch size is reached, timeout occurs, or shouldProcess returns true, the batch will be processed
TValue
Promise<any>
The result from the batch function, or undefined if an error occurred and was handled by onError
The error from the batch function if no onError handler is configured or throwOnError is true
ts
const batchItems = asyncBatch<number>(
async (items) => {
const result = await processApiCall(items);
console.log('Processing:', items);
return result;
},
{
maxSize: 3,
wait: 1000,
onSuccess: (result) => console.log('Batch succeeded:', result),
onError: (error) => console.error('Batch failed:', error)
}
);
batchItems(1);
batchItems(2);
batchItems(3); // Triggers batch processing
const batchItems = asyncBatch<number>(
async (items) => {
const result = await processApiCall(items);
console.log('Processing:', items);
return result;
},
{
maxSize: 3,
wait: 1000,
onSuccess: (result) => console.log('Batch succeeded:', result),
onError: (error) => console.error('Batch failed:', error)
}
);
batchItems(1);
batchItems(2);
batchItems(3); // Triggers batch processing
