如何阻止es6承诺流程执行?

时间:2015-10-25 09:31:43

标签: javascript ecmascript-6 es6-promise

如何在没有.catch函数执行的情况下停止Promise.then执行?

Promise
.resolve("a")
.then(function(a){
    console.log("step1 = " + a);
    return a;
})
.then(function(a){
    console.log("step2 = " + a);
    if (!someReason) {                
        return Promise.reject(); // I whant to stop flow execution here
    }        
})
.then(function(a){
    console.log("step3 = " + a);
    return a;
})
.catch(function(err){
// I don't whant to have .catch() executed in case of planned stop
   console.log("Flow failed");
});

0 个答案:

没有答案