alls

Just another library with the sole purpose of waiting till all promises to complete. Nothing more, Nothing less.

View the Project on GitHub

alls (All Settled) - wait till all the promises settled

License Version Language grade: JavaScript Codacy Badge Codacy Badge Build Status Known Vulnerabilities Maintainability

Just another library with the sole purpose of waiting till all promises to complete. Nothing more, Nothing less.

(Since, The Promise.all() method returns a single Promise that resolves when all of the promises passed as an iterable have resolved or when the iterable contains no promises. It rejects with the reason of the first promise that rejects.)

TypeScript Doc: https://rpgeeganage.github.io/alls/doc/

Basic Usage:

const { alls } = require('alls');

const results = await alls([promise1, promise2, .....promiseN]);
// structure of results
[
  {
    status: 'fulfilled',
    value: promise1-value
  },
  {
    status: 'rejected',
    reason: error-from-promise2
  }
...
  {
    status: 'fulfilled',
    value: promiseN-value
  }
]

Return value for Resolve

{
    status: 'fulfilled',
    value: <promise return value>
}

Return value for Reject

{
    status: 'rejected',
    reason: <Error thrown by promise>
}

final output

const error1 = new Error('error 1');
const error2 = new Error('error 2');
const error3 = new Error('error 3');

const results = await alls([
  Promise.resolve(1),
  Promise.reject(error1),
  Promise.resolve(2),
  Promise.reject(error2),
  Promise.resolve(3),
  Promise.reject(error3)
]);

/**
* content of the 'result'
*/
[
  { state: 'fulfilled', value: 1 },
  { state: 'rejected', reason: error1 },
  { state: 'fulfilled', value: 2 },
  { state: 'rejected', reason: error2 },
  { state: 'fulfilled', value: 3 },
  { state: 'rejected', reason: error3 }
]