Another promise limiter (adding concurrency to promises). This library uses rxjs to control concurrency, it also adds a little bit of extra functionality around how you get the results.
To install this package, run,
npm install --save promax
Once it's installed, you can use
Promax to run your promises with a specified concurrency value.
Assume we have the following promise function:
Promax is able to run this function concurrently in multiple ways:
NOTE: In this case, if a promise is rejected, it'll throw an error and end the call.
If we don't want to throw an error, we can pass a parameter object with
throws: false to the create function:
When it doesn't throw, it wraps errored results in an
ErrorResult instance. Using
instanceof ErrorResult will tell you whether or not there was an error in your array of results. Let's assume we have the following promise function which rejects:
Then we may get the following:
IMPORTANT: If you don't need the functionality above, you can chain everything into one call:
And you can send in the result map by reference: