I have checked through some of the suggested approaches for conditional chaining of promises however I could not find a solution for the use-case I have. Hence posting a fresh question.
Suppose I have:
const promise1 = param1 => {
return new Promise(resolve => {
// do something with param1;
resolve(..);
});
}
// similarly I have other promises
const promise2 ...
const promise 3 ...
// now I want to call with the following case
const param1 = ...;
promise1(param1)
.then(resp1 => {
if(resp1 == something) {
...
console.log(resp1) // I want to end here if condition is met
}
else {
...
return promise2
}
})
.then(resp2 => {
....
return promise3
})
.then(resp3 => {
....
console.log(resp3) // else end here
}).
.catch(err => {
console.log(err)
});
In the above if promise1 returns a specific value I do not want to proceed with promise2 and 3. What is the most elegant way to achieve this? Thanks