I had a problem with catching all errors in case of multiple errors reject rejection promises after waiting in async function (javaScript - node v8.4.0).
Make a link to the following javaScript:
For reference, the functions timeoutOne () and timeoutTwo () simply return their own promise, which resolves the value after a timeout of 1 and 2 seconds, respectively, or rejects with an error if I set "deviousState" to true.
let deviousState = true;
async function asyncParallel() {
try {
let res1 = timeoutOne();
let res2 = timeoutTwo();
console.log(`All done with ${await res1} ${await res2}`)
}
catch(err) {
console.log(err)
}
}
asyncParallel();
let pAll = Promise.all([timeoutOne(), timeoutTwo()]);
pAll.then((val) => {
console.log(`All done with ${val[0]} ${val[1]}`)
}).catch(console.log);
In both cases, only a promise that returns first logs the error. I know that in some promise libraries there is a way to register all errors (for example, the "install" method in bluebird), but I'm not sure if there is an analogue of this method in native promises?
, promises , asyncParallel() , . , try/catch , ?
, promises. , , Promise.all , async , node.
, try/catch ? Promise.all , , ?