Let's say I have three async
functions set as below:
const stepOne = async () => { setTimeout(function() {
console.log("step 1")
}, 3000) }
const stepTwo = async () => { throw new Error("Error at step two") }
const stepThree = async () => { console.log("step 3") }
How will I execute all these functions sequentially and break the promise chain at stepTwo not allowing stepThree function to run ever?
So,
normal sequence is like this: stepOne --> stepTwo --> stepThree
sequence with error thrown at stepTwo: stepOne --> stepTwo
The error thrown at stepTwo needs to get caught at end catch block.
UPDATE #1: Missed a crucial element of the question. await cannot be used as these three functions need to be called within a function which is not async.
example:
const testFunc = () => {
resolve three promises
sequentially, break the promise chain when error is thrown
and ultimately, catch errors here
}