Remix.run Logo
MatmaRex 3 days ago

You can await in a normal function in better languages, just not in JavaScript.

egeozcan 3 days ago | parent [-]

> Why can't I await in a normal function? await sounds blocking

> You can await in a normal function in better languages, just not in JavaScript.

Await, per common definition, makes you wait asynchronously for a Task/Promise. How on earth are you going to "await" for a Promise which also runs on the same thread on a synchronous function? That function needs to be psuedo-async as in "return myPromise.then(() => { /* all fn code here */ }), or you need to use threads, which brings us to the second point...

With the closest thing to threads (workers) in JavaScript and using SharedArrayBuffer and a simple while loop, perhaps (didn't think too much on it), you can implement the same thing with a user defined Promise alternative but then why would you want to block the main thread which usually has GUI/Web-Server code?

MatmaRex 2 days ago | parent [-]

It seemed to me that the previous poster wanted a way to wait for the result of a promise (in a blocking manner), and I meant that this is available in other languages. You're right that it is not usually spelled "await".