Found pretty strange behavior of Javascript Promise.all() when catch() method fires after first single promise and before all others. Did anyone found such strange thing before? I'm wondering what's happening behind this?
let promises = [];
[1, 2, 3].forEach((value) => {
const promise = new Promise((s, e) => {
setTimeout(() => {
e('Single Catch ' + value);
}, Math.random() * 100);
}).catch((err) => {
console.log(err);
return Promise.reject(err);
});
promises.push(promise);
});
Promise.all(promises).catch((err) => {
console.log('All Done');
});
Expected result would be:
- Single Catch X
- Single Catch X
- Single Catch 1
- All Done
Bu instead we get:
- Single Catch X
- All Done
- Single Catch X
- Single Catch X