I have a very simple JavaScript chain, much simpler than the previous similar questions' code: a, b, c. So I am wondering perhaps there might be a simpler answer as well.
Here is my promise chain, with Mongoose.
var someValue = 314;
// 1st promise
var promiseStep1 = step1.find({}).exec();
promiseStep1.then(function(doc1){
// do stuff with doc1
if (doc1 == someValue){
// HOW DO I BREAK OUT OF THE PROMISE CHAIN
// and not execute the 2nd and 3rd promises below?
}
// 2nd promise
return step2.find({}).exec();
}).then(function(doc2){
// do stuff with doc2
// 3rd promise
return step3.find({}).exec();
}).then(function(doc3){
// do stuff with doc3
// we're all done here
// handles error for all the promises
}, function(err){
return err;
});
How do I break out of the promise chain in the if (doc1 == someValue)
condition so that the latter promises don't get executed?