JSFiddle - React, Tailwind, and code Playground
JavaScript
function methodA () {
console.log('called A');
return Promise.resolve('not result');
}
function methodB () {
console.log('called B');
return Promise.resolve('result');
}
function isValid (result) {
return result === 'result';
}
async function getResult () {
let result = await methodA();
if (!isValid(result)) result = await methodB();
console.log('result', result);
}
getResult();