I am using promise code especially using Promise.all()
In one of the function I called reject state, so once reject(failure) state executed, it will catch the error message and the rest of the promises should not be executed. This is the rule in promise. But in my code, I called the reject state. Catch function catches the error message. Ok fine. But again control goes to other promises and printing the log statements in my code. Can anyone explain why?
var p1 = new Promise(function(resolve, reject) {
setTimeout(function() {
console.log("One dude");
resolve("one");
}, 3000);
});
var p2 = new Promise(function(resolve, reject) {
setTimeout(function() {
reject("TWO");
}, 1000);
});
var p3 = new Promise(function(resolve, reject) {
setTimeout(function() {
console.log("Three dude");
resolve("Three");
}, 4000);
});
Promise.all([p1, p2, p3]).then(function(msg) {
console.log(msg);
}).catch(function(err) {
return console.log(err);
});
I'm getting the output:
TWO
One dude
Three dude
I'm expecting output
TWO