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.