OK. Something I don't understand about promises. Here is the code:
function A() {
return new Promise(function(resolve, reject) {
setTimeout(function () {
reject(1000);
}, 1000);
});
}
function B() {
return new Promise(function(resolve, reject) {
setTimeout(function () {
reject(2000);
}, 2000);
});
}
function C() {
return new Promise(function(resolve, reject) {
setTimeout(function () {
reject(3000);
}, 3000);
});
}
function D() {
return new Promise(function(resolve, reject) {
setTimeout(function () {
reject(4000);
}, 4000);
});
}
function ABCD() {
var workqueue = [
A,
B,
C,
D
];
return Promise.all(workqueue.map(function(work) {
return work();
})).catch(function(err) {
return err;
});
}
ABCD().then(function(result) {
console.log(result);
}).catch(function(err) {
console.log(err);
});
Each function is called but my understanding is that when any (the first) is rejected then the 'all' promise is in error. What I am seeing from the above is that instead of the result showing up in the catch block the "rejection" shows up in the normal resolve. How can I get it to show up in the catch as an error?
Thank you.