promise-call-limit
Call an array of promise-returning functions, restricting concurrency to a specified limit.
Last updated 10 months ago by isaacs .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install promise-call-limit 
SYNC missed versions from official npm registry.

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<Object>)

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.

Current Tags

  • 3.0.2                                ...           latest (2 months ago)

6 Versions

  • 3.0.2                                ...           2 months ago
  • 3.0.1                                ...           10 months ago
  • 2.0.0                                ...           10 months ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Total 5
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)
  • prettier ^3.2.1
  • tap ^18.6.1
  • tshy ^1.8.2
  • format prettier --write . --loglevel warn --ignore-path ../../.prettierignore --cache
  • typedoc typedoc
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE