Say someone implemented a different setTimeout function:
const setTimeout = (func, ms) => {
const future = Date.now() + ms;
while (Date.now() < future) {
// do nothing
}
func();
};
Which (for the simplicity of this question) has almost the same interface as the original one. How can I, as a developer using it, can verify it did not initialize any async code?
I want to know if my program will exist after I use the setTimeout
call.
If the setTimeout
is implemented using sync code, the program will exist (shortly) after.
If the implemenation of setTimeout
is async, the program will exist only after the async code is done.
More specifically, can I do something like that?
setTimeout(()=>{},1000);
const isAnyAsyncCodeWillRun = ...;
if(isAnyAsyncCodeWillRun){
console.log('Program wont exist right now, only in about 1000ms');
} else {
console.log('Program will exist now');
}