Executes an array of promises and returns their resolved or rejected results.
npm install --save @trenskow/results
const results = ;
Getting all Results
const resolved rejected =;/* -> [['a','b'],[Error('a'), Error('b')]] */
Getting Only Resolved Results
const resolved = results;/* -> ['a','b'] */
Getting Only Rejected Results
const rejected = results;/* -> [Error('a'),Error('b')] */
The promises are executed in serial and therefore out-of-order, meaning there is no guarantee in which order the result comes out.
Executing in Parallel
You can specify how many promises can be executed at once by using an option.
const resolved rejected = ;
The above example will make the promises execute one at the time (which also guarantees order). You can specify any arbitrary number, default is
0, which is equal to unlimited.
This works for all three variants (resolved/rejected, resolved and rejected).
MIT (see license).