Re:Rust’s async isn’t colored
by resonantjacket5 on Thursday March 11, 2021 @01:43PM
(#26427435)
You can technically wrap the promise and spin lock on it till it resolves. Aka forcibly wait on an async function in a sync function. There are some npm libraries that provide it. I've used a couple times (for some hacky scripts), though obviously don't use it in the browser.
[ Parent
| on HN ]
AFAIK, you can't do this from JS, you have to have some engine integration, as the busy loop in JS will prevent the event loop from working.
For instance, this will essentially halt your runtime:
let y;
Promise.resolve(123).then(x => { y = x; });
while (!y) {}
console.log(y)Yes, deasync[0] for example, hooks into the Node.js event loop from c++ land