function createAsyncBatcher<TValue, TSelected>(
fn,
initialOptions,
selector?): SolidAsyncBatcher<TValue, TSelected>
function createAsyncBatcher<TValue, TSelected>(
fn,
initialOptions,
selector?): SolidAsyncBatcher<TValue, TSelected>
Defined in: async-batcher/createAsyncBatcher.ts:82
Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.
This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:
Features:
The batcher collects items and processes them in batches based on:
Error Handling:
Example usage:
// Basic async batcher for API requests
const asyncBatcher = createAsyncBatcher(
async (items) => {
const results = await Promise.all(items.map(item => processItem(item)));
return results;
},
{
maxSize: 10,
wait: 2000,
onSuccess: (result) => {
console.log('Batch processed successfully:', result);
},
onError: (error) => {
console.error('Batch processing failed:', error);
}
}
);
// Add items to batch
asyncBatcher.addItem(newItem);
// Manually execute batch
const result = await asyncBatcher.execute();
// Use Solid signals in your UI
const items = asyncBatcher.state().items;
const isExecuting = asyncBatcher.state().isExecuting;
// Basic async batcher for API requests
const asyncBatcher = createAsyncBatcher(
async (items) => {
const results = await Promise.all(items.map(item => processItem(item)));
return results;
},
{
maxSize: 10,
wait: 2000,
onSuccess: (result) => {
console.log('Batch processed successfully:', result);
},
onError: (error) => {
console.error('Batch processing failed:', error);
}
}
);
// Add items to batch
asyncBatcher.addItem(newItem);
// Manually execute batch
const result = await asyncBatcher.execute();
// Use Solid signals in your UI
const items = asyncBatcher.state().items;
const isExecuting = asyncBatcher.state().isExecuting;
• TValue
• TSelected = AsyncBatcherState<TValue>
(items) => Promise<any>
AsyncBatcherOptions<TValue> = {}
(state) => TSelected
SolidAsyncBatcher<TValue, TSelected>
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.