Re:Rust’s async isn’t colored
by resonantjacket5 on Thursday March 11, 2021 @11:07AM
(#26425503)
"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.
[ Parent
| on HN ]
Does 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..It 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