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

run-with-limit

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

run-with-limit

Run promises with limited concurrency

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Run with limit

Run multiple promise-returning & async functions with limited concurrency. Heavily inspired by sindresorhus/p-limit.

Usage

import { makeRunWithLimit } from "https://denopkg.com/alextes/run-with-limit";

const { runWithLimit } = makeRunWithLimit(1);

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

API

makeRunWithLimit(concurrency)

Number => { runWithLimit, getActiveCount, getPendingCount }

Takes a number, setting the concurrency for the promise queue. Returns a set of functions to use the queue.

runWithLimit

<A>(() => Promise<A>) => Promise<A>

Pass a thunk to this function that returns a promise.

That is, pass a function which when invoked, kicks off an asynchronous computation, and if you need its result, returns a promise. runWithLimit will resolve with said result while honoring the concurrency limit.

getActiveCount

() => Number

Call to get the number of promises that are currently running.

getPendingCount

() => Number

Call to check how many promises are still waiting to start execution.

FAQs

Package last updated on 27 May 2020

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