Access Result Of Previous Promise Inside A Second
I'm using the return pattern to prevent me from making promise ugly cascade. Here is an exemple, I'm calling two function one after the other myfunction1 and myfunction2 myfunction
Solution 1:
You must pass it through your chain. That's why I started using async/await
:
try {
var value1 = awaitmyfunction1();
var value2 = awaitmyFunction2();
console.log(value1)
} catch (err) {
console.error(err)
}
Solution 2:
you have to "chain" your promises like this:
myfunction1().then((value1) => {
returnmyfunction2().then((value2) => {
console.log(value1)
})
}).catch((err) => {
console.error(err)
}
Post a Comment for "Access Result Of Previous Promise Inside A Second"