alls
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

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 }
]

Dependents (0)

Package Sidebar

Install

npm i alls

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

9.63 kB

Total Files

6

Last publish

Collaborators

  • rpg