79398072

Date: 2025-01-29 20:16:13
Score: 2
Natty:
Report link

How do I achieve the following, making sure functionB() executes after functionA() finishes?

I think what you want is a third async function and then call that one. Like this:

function functionThatCannotHaveAsyncKeyword() {
    functionC()
    .then((resp) =>{
        // this code will execute after functioA and fucntionB finish. 
        // They will execute in that order thanks to functionC.
    });
}

async function functionC() {
    await functionA();
    await functionB();
}

async function functionA() {
    console.log('first');
    await someServiceThatMakesHTTPCall();
}

async function functionB() {
    console.log('second');
    await someServiceThatMakesHTTPCall();
}
Reasons:
  • Blacklisted phrase (0.5): thanks
  • Blacklisted phrase (1): How do I
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How do I
  • Low reputation (0.5):
Posted by: Jose Luis Quiroga Beltran