I am using Bluebird as
the main promise library for
my Node projects these days.
I frequently use
resolve multiple promises in an array or an object at once.
This is fine if there is not limit to the number of promises
your system can handle. Often, this is not the case.
For example, it’s not a good idea to resolve 1K requests at once.
This is when you want to use concurrency provided by Bluebird.
Dealing with an Array of Promises
Let’s say we used to resolve an array of promises naively this way.
Better way to handle this is with concurrency. In this example, we will resolve 4 at a time. If you want to resolve the promises one at a time, you will want to use the concurrency of 1.
Dealing with an Object of Promises
If the number of promises in the object is small, you can use
to resolve them.
Bluebird doesn’t have a direct way to resolve an object of promises
concurrently, but here is a way to do it with
map. Resolving an object
of promises using concurrency looks something like this.