4 ms·
"does not allow in any way calling promise/async/callback" To be accurate you can wrap your promise with a spin lock and wait on it if you really really want to
by resonantjacket5 6y ago
"does not allow in any way calling promise/async/callback" To be accurate you can wrap your promise with a spin lock and wait on it if you really really want to. It's just a horrible idea for the browser. But yes you can wait on async functions if desired, the js language doesn't actually prevent it, there's just no built-in feature.
- _flux 6y agoDoes this actually work, though? I would expect it to fail similarly as this fails (note, may hang your browser or a tab, depending on your browser): var foo = [0]; function setFoo() { console.log("Callback"); foo[0] = 1; } setTimeout(setFoo, 100); console.log("Waiting.."); while (!foo[0]); console.log("Done."); Edited the original message with reversed arguments to setTimeout; doesn't seem to affect the results though. Really need to love the complete lack of error messages though..
- kuschku 6y agoIt doesn't, as promise resolution and execution is scheduled as new tasks on the main thread, which are only ever run if the currently executing piece of code finishes. That's pretty much identical between IO, setTimeout/setInterval and requestAnimationFrame