How to skip promise in a chain
Simply nest the part of the chain you want to skip (the remainder in your case):
new Promise(resolve => resolve({success:true}))
.then(value => {
console.log('second block:', value);
if (value.success) {
//skip the rest of this chain and return the value to caller
return value;
}
//do something else and continue
return somethingElse().then(value => {
console.log('3rd block:', value);
return value;
});
}).then(value => {
//The caller's chain would continue here whether 3rd block is skipped or not
console.log('final block:', value);
return value;
});
If you don't like the idea of nesting, you can factor the remainder of your chain into a separate function:
// give this a more meaningful name
function theRestOfThePromiseChain(inputValue) {
//do something else and continue next promise
console.log('3rd block:', value);
return nextStepIntheProcess()
.then(() => { ... });
}
function originalFunctionThatContainsThePromise() {
return Promise.resolve({success:true})
.then((value)=>{
console.log('second block:', value);
if(value.success){
//skip the rest of promise in this chain and return the value to caller
return value;
}
return theRestOfThePromiseChain(value);
});
}
Aside from that, there isn't really a way to stop a promise mid-stream.