$ npm install promise-call-limit
Call an array of promise-returning functions, restricting concurrency to a specified limit.
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))
opts can contain:
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.
© 2010 - cnpmjs.org x YWFE | Home | YWFE