
Security News
pnpm 10.12 Introduces Global Virtual Store and Expanded Version Catalogs
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
The pend npm package is designed to manage and limit the concurrency of asynchronous operations in Node.js applications. It provides a simple API to queue tasks and control how many of them are executed in parallel, making it easier to manage resources and improve the performance of applications that perform a lot of asynchronous operations, such as file I/O or network requests.
Limiting concurrency of asynchronous operations
This code sample demonstrates how to use pend to limit the concurrency of asynchronous operations. It creates a new Pend instance, sets a concurrency limit, and then queues several asynchronous operations. Pend ensures that only a specified number of operations run in parallel, and provides a callback for when all operations are completed.
const Pend = require('pend');
const pend = new Pend();
pend.max = 2; // Limit to 2 concurrent operations
function asyncOperation(callback) {
setTimeout(() => {
console.log('Operation completed');
callback();
}, 1000);
}
for (let i = 0; i < 5; i++) {
pend.go((cb) => {
asyncOperation(cb);
});
}
pend.wait(() => {
console.log('All operations completed');
});
The async package is a comprehensive collection of utility functions for working with asynchronous JavaScript. It includes features for controlling the flow of asynchronous operations, such as limiting concurrency, similar to pend. However, async offers a broader range of functionalities beyond concurrency control, making it more versatile but also more complex.
p-limit is a lightweight package specifically designed to limit the concurrency of promise-returning & async functions. It is very similar to pend in its purpose but works with Promises instead of callbacks, making it more suitable for modern asynchronous patterns in JavaScript.
Dead-simple optimistic async helper.
var Pend = require('pend');
var pend = new Pend();
pend.max = 10; // defaults to Infinity
setTimeout(pend.hold(), 1000); // pend.wait will have to wait for this hold to finish
pend.go(function(cb) {
console.log("this function is immediately executed");
setTimeout(function() {
console.log("calling cb 1");
cb();
}, 500);
});
pend.go(function(cb) {
console.log("this function is also immediately executed");
setTimeout(function() {
console.log("calling cb 2");
cb();
}, 1000);
});
pend.wait(function(err) {
console.log("this is excuted when the first 2 have returned.");
console.log("err is a possible error in the standard callback style.");
});
Output:
this function is immediately executed
this function is also immediately executed
calling cb 1
calling cb 2
this is excuted when the first 2 have returned.
err is a possible error in the standard callback style.
FAQs
dead-simple optimistic async helper
The npm package pend receives a total of 15,182,916 weekly downloads. As such, pend popularity was classified as popular.
We found that pend 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
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.