Socket
Socket
Sign inDemoInstall

promise-call-limit

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

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.


Version published
Maintainers
1
Weekly downloads
1,838,901
decreased by-10.38%

Weekly downloads

Readme

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

Last updated on 13 Jan 2024

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