Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-limit

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-limit

Run multiple promise-returning & async functions with limited concurrency

  • 6.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
135M
increased by2.05%
Maintainers
1
Weekly downloads
 
Created

What is p-limit?

The p-limit npm package is a utility that allows you to limit the number of promises that are running at the same time. It is useful for controlling concurrency when you have operations that can be run in parallel but you want to limit the number of these operations due to resource constraints.

What are p-limit's main functionalities?

Concurrency Limiting

This feature allows you to create a limit for how many promises are allowed to run at once. In the code sample, the limit is set to 1, meaning that `doSomething` and `doAnotherThing` will not run at the same time.

const pLimit = require('p-limit');
const limit = pLimit(1);

async function doSomething() {}

async function doAnotherThing() {}

// Only one promise will run at once
const result1 = limit(() => doSomething());
const result2 = limit(() => doAnotherThing());

Queueing

This feature demonstrates how additional promises are queued when the limit is reached. In this example, only two promises will run concurrently, and the rest will wait in the queue.

const pLimit = require('p-limit');
const limit = pLimit(2);

const input = [
  limit(() => fetchSomething('foo')),
  limit(() => fetchSomething('bar')),
  limit(() => doSomethingElse()),
];

// Only two promises will run at once, the rest will be queued
Promise.all(input).then(results => {
  console.log(results);
});

Other packages similar to p-limit

Keywords

FAQs

Package last updated on 08 Jul 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc