bulk-processor
v3.0.1
Published
A simple batch executor with size and timeout control.
Downloads
12
Maintainers
Readme
Bulk Processor
A lightweight utility to process items in bulk with size and time constraints.
Useful for batching operations such as API calls, database writes, or logging.
📦 Installation
npm install bulk-processor
# or
yarn add bulk-processor🚀 Usage
JavaScript (CommonJS)
const { BulkProcessor } = require('bulk-processor');
const processor = BulkProcessor(5, 2000, async (batch) => {
console.log('Processing batch:', batch);
});
processor.push(1);
processor.push(2);
processor.push(3);
// Flush manually if needed
await processor.flush();TypeScript / ESM
import { BulkProcessor } from 'bulk-processor';
const processor = BulkProcessor(5, 2000, async (batch) => {
console.log('Processing batch:', batch);
});
processor.push(42);
processor.push(99);
await processor.flush();⚙️ API
BulkProcessor(size, timeout, batchFunc)
| Parameter | Type | Description |
| --- | --- | --- |
| size | number | Maximum number of items per batch |
| timeout | number | Maximum time in milliseconds before a batch is processed |
| batchFunc | (items: T[]) => Promise | Function to process a batch of items (called automatically or on flush) |
Returns
An object with methods:
push(item: T): void→ Add an item to the batchflush(): Promise<void>→ Immediately process current batch
📘 Example Use Cases
- Buffering API calls to avoid rate limits
- Grouping database inserts for performance
- Logging events in bulk
📄 License
MIT © canhhungit
