npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

batch-process-manager

v0.0.8

Published

Batch multiple requests together with configurable timeouts and concurrency limits to optimize API calls and database queries.

Readme

Batch Process Manager

Batch multiple requests together with configurable timeouts and concurrency limits to optimize API calls and database queries.

Features

  • Automatic Batching: Collects individual requests into batches for efficient processing
  • Configurable Batch Size: Control how many requests are processed together
  • Timeout Management: Automatically processes incomplete batches after a specified timeout
  • Concurrency Control: Limit the number of concurrent batch operations
  • Type Safety: Full TypeScript support with proper generic types
  • Promise-based: Simple async/await interface

Installation

NPM

npm install batch-process-manager

GitHub

npm i https://github.com/lacherogwu/batch-process-manager

Usage

Basic Example

import { BatchManager } from 'batch-process-manager';

// Create a batch manager
const batchManager = new BatchManager({
	processBatch: async batchKeys => {
		// Your batch processing logic here
		// This should return a Map where keys match the input keys
		const results = new Map();

		// Example: fetch data for multiple keys at once
		const data = await fetchMultipleItems(batchKeys);

		batchKeys.forEach((key, index) => {
			results.set(key, data[index]);
		});

		return results;
	},
	batchSize: 10, // Process 10 items at once
	batchTimeout: 1000, // Wait max 1 second before processing incomplete batch
	concurrency: 5, // Allow up to 5 concurrent batch operations
});

// Use the batch manager
const result = await batchManager.get('item-key');
console.log(result);

Advanced Example

import { BatchManager } from 'batch-process-manager';

// Example: Batch API requests for product data
const productBatchManager = new BatchManager({
	processBatch: async productIds => {
		// Make a single API call for multiple products
		const response = await fetch('/api/products', {
			method: 'POST',
			headers: { 'Content-Type': 'application/json' },
			body: JSON.stringify({ ids: productIds }),
		});

		const products = await response.json();
		const resultMap = new Map();

		products.forEach(product => {
			resultMap.set(product.id, product);
		});

		return resultMap;
	},
	batchSize: 20,
	batchTimeout: 500,
	concurrency: 3,
});

// Process multiple requests efficiently
const promises = [];
for (let i = 1; i <= 100; i++) {
	promises.push(productBatchManager.get(`product-${i}`));
}

const products = await Promise.all(promises);
console.log(`Fetched ${products.length} products`);

Configuration Options

BatchManagerOpts<T>

| Option | Type | Default | Description | | -------------- | ---------------------------------------------------- | ------------ | -------------------------------------------------------------------- | | processBatch | (batchKeys: string[]) => Promise<Map<string, any>> | Required | Function that processes a batch of keys and returns a Map of results | | batchSize | number | 20 | Maximum number of requests to process in a single batch | | batchTimeout | number | 1000 | Time in milliseconds to wait before processing an incomplete batch | | concurrency | number | Infinity | Maximum number of batch operations to run in parallel |

How It Works

  1. Request Accumulation: When you call get(key), the request is added to the current batch
  2. Batch Triggering: A batch is processed when either:
    • The batch reaches the configured batchSize
    • The batchTimeout expires
  3. Concurrent Processing: Multiple batches can be processed simultaneously up to the concurrency limit
  4. Result Distribution: Results from the batch processing function are distributed back to the individual promise resolvers

Use Cases

  • API Rate Limiting: Reduce API calls by batching requests
  • Database Queries: Batch database lookups for better performance
  • Data Fetching: Optimize data fetching in applications with many concurrent requests

Error Handling

If the processBatch function throws an error, all requests in that batch will be rejected with the same error. If a specific key is not found in the returned Map, that individual request will resolve with undefined.

try {
	const result = await batchManager.get('non-existent-key');
	if (result === undefined) {
		console.log('Key not found, but no error thrown');
	}
} catch (error) {
	console.error('Request failed:', error.message);
}

TypeScript Support

The library provides full TypeScript support with proper generic types:

type MyDataType = { id: string; name: string; price: number };

const typedBatchManager = new BatchManager({
	processBatch: async (keys: string[]): Promise<Map<string, MyDataType>> => {
		// Implementation here
		return new Map();
	},
});

// result is properly typed as MyDataType
const result = await typedBatchManager.get('key');

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.