function createBatcher<TValue>(fn, initialOptions): SolidBatcher<TValue>
function createBatcher<TValue>(fn, initialOptions): SolidBatcher<TValue>
Defined in: batcher/createBatcher.ts:90
Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
Features:
The batcher collects items and processes them in batches based on:
Example usage:
const batcher = createBatcher(
(items) => {
// Process batch of items
console.log('Processing batch:', items);
},
{
maxSize: 5,
wait: 2000,
onExecute: (batcher) => console.log('Batch executed'),
getShouldExecute: (items) => items.length >= 3
}
);
// Add items to batch
batcher.addItem('task1');
batcher.addItem('task2');
// Control the batcher
batcher.stop(); // Pause processing
batcher.start(); // Resume processing
// Access batcher state via signals
console.log('Items:', batcher.allItems());
console.log('Size:', batcher.size());
console.log('Is empty:', batcher.isEmpty());
console.log('Is running:', batcher.isRunning());
console.log('Batch count:', batcher.batchExecutionCount());
console.log('Item count:', batcher.itemExecutionCount());
const batcher = createBatcher(
(items) => {
// Process batch of items
console.log('Processing batch:', items);
},
{
maxSize: 5,
wait: 2000,
onExecute: (batcher) => console.log('Batch executed'),
getShouldExecute: (items) => items.length >= 3
}
);
// Add items to batch
batcher.addItem('task1');
batcher.addItem('task2');
// Control the batcher
batcher.stop(); // Pause processing
batcher.start(); // Resume processing
// Access batcher state via signals
console.log('Items:', batcher.allItems());
console.log('Size:', batcher.size());
console.log('Is empty:', batcher.isEmpty());
console.log('Is running:', batcher.isRunning());
console.log('Batch count:', batcher.batchExecutionCount());
console.log('Item count:', batcher.itemExecutionCount());
• TValue
(items) => void
BatcherOptions<TValue> = {}
SolidBatcher<TValue>
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.