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

promise-call-limit

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-call-limit

Call an array of promise-returning functions, restricting concurrency to a specified limit.

  • 3.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

promise-call-limit

Call an array of promise-returning functions, restricting concurrency to a specified limit.

USAGE

import { callLimit } from 'promise-call-limit'
// or: const { callLimit } = require('promise-call-limit')

const things = getLongListOfThingsToFrobulate()

// frobulate no more than 4 things in parallel
callLimit(
  things.map(thing => () => frobulateThing(thing)),
  {
    limit: 4,
  },
).then(results => console.log('frobulated 4 at a time', results))

API

callLimit(queue Array<() => Promise>, opts)

opts can contain:

  • limit: specified concurrency limit. Defaults to the number of CPUs on the system minus one. Presumably the main thread is taking up a CPU as well, so let's not be greedy. In the case where there is only one cpu the limit will default to 1.
  • rejectLate: if true, then any rejection will not prevent the rest of the queue from running. Any subsequent rejections will be ignored, and the first rejection will be what the function finally rejects with.

Note that the array should be a list of Promise-returning functions, not Promises themselves. If you have a bunch of Promises already, you're best off just calling Promise.all().

The functions in the queue are called without any arguments.

FAQs

Package last updated on 08 Sep 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