
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
bulk-processor1
Advanced tools
A simple batch executor with size and timeout control.
A simple and efficient bulk processor with size and timeout control, powered by lodash
's throttle function. This package helps you process items in batches, improving performance and reducing the load on resources when dealing with large datasets or asynchronous operations.
Install the package using npm:
npm install bulk-processor
Here's a simple example of how to use the bulk processor:
const { BulkProcessor } = require('bulk-processor');
// Example batch processing function
async function processBatch(batch) {
console.log('Processing batch:', batch);
// Simulate some asynchronous work
await new Promise((resolve) => setTimeout(resolve, 100));
}
// Create a bulk processor with a batch size of 5 and a 500ms timeout
const processor = BulkProcessor(5, 500, processBatch);
// Push some items into the batch
for (let i = 0; i < 20; i++) {
processor.push(i);
}
// Flush remaining items and log the total processed count after 1 second
setTimeout(async () => {
await processor.flush();
}, 1000);
BulkProcessor(size, timeout, batchFunc)
Creates a new bulk processor instance.
size
: number
- The maximum size of a batch.timeout
: number
- The minimum time interval in milliseconds between batch executions.batchFunc
: async function
- The function to call with each batch. This function receives the batch as a single argument (an array of items).push(item)
Adds an item to the current batch. If the batch reaches the maximum size, it will be flushed, or if a timeout expires, it also will be flushed.
item
: any
- The item to add to the batch.flush()
Forces the current batch to be processed immediately. If you don't call flush()
manually, the final batch might not be processed. This method returns a Promise
which resolves when the batch is processed.
Promise
This example shows the basic usage of the processor with the default configuration.
const { BulkProcessor } = require('bulk-processor');
async function processBatch(batch) {
console.log('Processing batch:', batch);
await new Promise((resolve) => setTimeout(resolve, 100));
}
const processor = BulkProcessor(3, 200, processBatch);
for (let i = 0; i < 10; i++) {
processor.push(i);
}
This example demonstrates how to customize the batch size and timeout.
const { BulkProcessor } = require('bulk-processor');
async function processBatch(batch) {
console.log('Processing batch:', batch);
await new Promise((resolve) => setTimeout(resolve, 50));
}
const processor = BulkProcessor(10, 1000, processBatch); // Batch size 10, timeout 1 second
for (let i = 0; i < 30; i++) {
processor.push(i);
}
// If you want to flush immediately even when there is data in batch
setTimeout(async () => {
await processor.flush();
}, 1000);
Contributions are welcome! Feel free to submit issues and pull requests.
This project is licensed under the MIT License.
FAQs
A simple batch executor with size and timeout control.
We found that bulk-processor1 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.