79095802

Date: 2024-10-16 20:58:28
Score: 0.5
Natty:
Report link

Colleagues,this is how it works as necessary:

const delay = (timeout = 0) => new Promise(r => setTimeout(r, timeout));
var StillWorking = false;
function First(){
  console.log('First started');
  StillWorking = true;
  setTimeout(Second, 1000);
  console.log('First fired Second and continue working');
  return;
}
function Second(){
  console.log('Second');
  StillWorking = false;
}
async function Main(){
    console.log('Main');
    First();
    while (StillWorking) await delay(10);
    console.log('All done');
}
Main();

First function should not wait until Second is finished. The only task is to make Main to wait for callong a function Second, so I canot use Promise when calling Second.

But all the code seems very dumb, with a global variable and infinite loop. Yet I do not see more accurate solution.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Dmitry Klavdiev