Socket
Socket
Sign inDemoInstall

pend

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pend

dead-simple optimistic async helper


Version published
Weekly downloads
15M
increased by0.37%
Maintainers
1
Install size
5.29 kB
Created
Weekly downloads
 

Package description

What is pend?

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.

What are pend's main functionalities?

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');
});

Other packages similar to pend

Readme

Source

Pend

Dead-simple optimistic async helper.

Usage

var Pend = require('pend');
var pend = new Pend();
pend.max = 10; // defaults to Infinity
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

Last updated on 05 Jul 2014

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc