Execute all the promises whether they resolve or reject
An alternative native solution for this library is Promise.allSettled.
// Yarn
yarn add promise-all-always
// NPM
npm install promise-all-always
const promiseAllAlways = require('promise-all-always');
// Even if second promise is rejected, the execution will continue
// Use "result" property to receive promise result
// Use "isResolved" property to check if the promise is resolved or rejected
promiseAllAlways([
Promise.resolve(1),
Promise.reject(0),
Promise.resolve('done')
]).then(values => {
for (let value of values) {
console.log(
`Result: ${value.result}`,
'\t',
`Promise is ${value.isResolved ? 'resolved' : 'rejected'}`
);
}
});
// Return raw values (no object)
promiseAllAlways([Promise.resolve(1), Promise.reject(0), Promise.resolve('done')], {rawResult: true})
.then(values => console.log('Raw result', values));
For more examples check examples folder.
// Yarn
$ yarn test
// NPM
$ npm test
Contributions to the package are always welcome!
- Report any bugs or issues you find on the issue tracker.
- You can grab the source code at the package's Git repository.
All contents of this package are licensed under the MIT license.