HackerTrans
TopNewTrendsCommentsPastAskShowJobs

Could JavaScript have synchronous await?(2ality.com)

4 points·by Kerrick·ปีที่แล้ว·1 comments
2ality.com
Could JavaScript have synchronous await?

https://2ality.com/2025/03/sync-await.html

1 comments

starmole·ปีที่แล้ว
You can emulate synchronous await by using a worker thread, marshal your async operation to the main thread, then in the worker use Atomics.wait() to blocking wait on a SharedArrayBuffer variable. Once the async operation completes on main, write back the result to the SharedArrayBuffer and wake up the waiting variable. I believe that's also what emscripten uses to emulate synchronous posix calls.