
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
@imrandil/concurrent-promise-batcher
Advanced tools
A utility for executing asynchronous tasks concurrently in batches, providing better control over resource usage and improved performance.
Concurrent Promise Batcher is a Node.js utility for executing asynchronous tasks concurrently in batches, providing better control over resource usage and improved performance. This package allows you to fetch data concurrently for multiple batches while managing the maximum number of concurrent promises being executed.
npm install concurrent-promise-batcher
const concurrentPromise = require('concurrent-promise-batcher');
// Define a function to execute for each item in the batch
async function fetchData(item) {
// Perform asynchronous operation (e.g., fetching data from an API)
// Return a Promise
}
// Define your batches
const batches = [/* Array of items representing each batch */];
// Set the maximum number of concurrent promises to execute
const batchConcurrency = 5;
// Execute promises concurrently for batches
concurrentPromise(batchConcurrency, batches, fetchData)
.then((result) => {
console.log('Results:', result.results);
console.log('Execution Time:', result.executionTime);
console.log('Number of Batches Processed:', result.numBatchesProcessed);
console.log('Average Execution Time per Batch:', result.avgExecutionTimePerBatch);
})
.catch((error) => {
console.error('Error:', error.message);
});
batchConcurrency
: The maximum number of concurrent promises to execute. Must be a positive integer.batches
: An array of items representing each batch. Must be a non-empty array.fn
: The function to execute concurrently for each batch item. Must be a function.settled
: Whether to use Promise.allSettled
or Promise.all
. Default is false
(Promise.all
).Promise.all
vs Promise.allSettled
By default, concurrentPromise
uses Promise.all
to await the fulfillment of all promises in each batch. This means that if any promise rejects (encounters an error), the entire batch will fail and the rejection will be propagated to the caller.
If you want to handle individual promise rejections separately or continue processing even if some promises fail, you can set the settled
parameter to true
. This will make concurrentPromise
use Promise.allSettled
instead. With Promise.allSettled
, the returned promise will fulfill with an array of objects representing the status of each promise, whether fulfilled or rejected.
FAQs
A utility for executing asynchronous tasks concurrently in batches, providing better control over resource usage and improved performance.
The npm package @imrandil/concurrent-promise-batcher receives a total of 0 weekly downloads. As such, @imrandil/concurrent-promise-batcher popularity was classified as not popular.
We found that @imrandil/concurrent-promise-batcher demonstrated a not healthy version release cadence and project activity because the last version was released 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
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.