I know that topic’s title is not clear. Maybe with an example…
constructor() {
this.methodA().then((result) => {
alert(result); // must alert "A" or "B"
});
}
methodA() {
return new Promise((resolve) => {
let someExpressionResult:boolean = false;
if(someExpressionResult) {
setTimeout(() => {
resolve('A');
}, 500)
} else {
return this.methodB(); // This is not working now!
}
});
}
methodB() {
return new Promise((resolve) => {
setTimeout(() => {
resolve('B');
}, 500)
});
}
In the code above, if someExpressionResult is set to true, we can see an alert with ‘A’ message.
Otherwise, if someExpressionResult is set to false, we can not see any alert. MethodA never ends.
How can I get it working?
Thanks in advance!