promise-fail
v1.0.2
Published
returns a single Promise that resolves when all of the promises in the iterable argument have been rejected.
Downloads
10
Readme
promise-fail
Promise.all for failures Check if all promises fail
> npm install promise-fail || yarn add promise-fail
Require module
Promise.fail = require('promise-fail'); // why not
// or
const checkPromisesFailure = require('promise-fail');
Usage
This module checks if all Promises given in arguments fail and returns the first non-failing Promise
const p1 = Promise.reject(true);
const p2 = Promise.reject(true);
const p3 = Promise.reject(true);
const p4 = Promise.resolve("YES");
// this will print 'All promises have failed'
Promise.fail([ p1, p2, p3 ])
.then(() => console.log("All promises have failed"))
.catch(promise => console.log(promise));
// this will print 'Promise { 'YES' }' or alike
Promise.fail([ p1, p4 ])
.then(() => console.log("All promises have failed"))
.catch(promise => console.log(promise));