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

plimit-lit

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

plimit-lit

This package is a helper to run multiple promise-returning & async functions with limited concurrency.

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
622K
increased by2.48%
Maintainers
1
Weekly downloads
 
Created
Source

plimit-lit

This package is a helper to run multiple promise-returning & async functions with limited concurrency.

Installation

$ npm i plimit-lit
# or
$ yarn add plimit-lit

Usage

import { pLimit } from 'plimit-lit';

const limit = pLimit(1);

(async () => {
	// NOTE: Only one promise is run at once
	const result = await Promise.all([
		limit(() => fetchSomething('foo')),
		limit(() => fetchSomething('bar')),
		limit(() => doSomething()),
	]);
	console.log(result);
})();

API

limit = pLimit(concurrency)

Returns a limit function to enqueue promise returning or async functions.

concurrency

Type: number

Number of the concurrency limit.

limit(fn, ...args)

Returns a promise returned from calling fn(...args).

fn

Type: Function

Promise-returning or async function.

args

Optional arguments fn is being called with.

Note: Support for passing arguments on to the fn is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a lot of functions.

limit.activeCount

Static method that returns the number of promises currently running.

limit.pendingCount

Static method that returns the number of promises currently waiting to be run (i.e. their internal fn was not called yet).

limit.clearQueue()

Clear the internal queue of promises. This discards pending promises that are waiting to be run.

Note: This does not cancel in-flight promises!

Development

(1) Install dependencies

$ npm i
# or
$ yarn

(2) Run initial validation

$ ./Taskfile.sh validate

(3) Start developing. See ./Taskfile.sh for more tasks to help you develop.

FAQs

Package last updated on 20 May 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