const items = [1, 2, 3, 4, 5]; // Array of arguments
const handleOneItem = async (item: number) => {
console.log(item);
};
await batch(handleOneItem, {
concurrency: 10,
items,
failureMode: 'continue',
onError: (error, item) => {
console.error(error, item);
},
onStart: (total) => {
console.log(`Starting batch with ${total} chunks`);
},
onEnd: (results) => {
console.log(`Batch completed with ${results.length} results`);
},
onChunkStart: ({ index, total, items }) => {
console.log(`Starting chunk ${index + 1}/${total}`);
},
onChunkEnd: ({ index, total, items }) => {
console.log(`Finished chunk ${index + 1}/${total}`);
}
});
Processes items in batches with configurable concurrency and error handling.
Provides progress tracking through lifecycle callbacks and supports different failure modes for robust batch processing.