6 ms·
Using asynchronous web APIs from WebAssembly
- richardanaya 6y agoI find it really crazy how far this had to go to support something as simple as sleep. I became aware of this problem when I started writing WASI last year. So so much unix code is based on the idea of synchronous operations. My conclusions were that some sort of ability to have atomics that could pause a web assembly running on a web worker while an async operation completed then unlocked the blocked web assembly was the only way this could be sanely done.
- lucideer 6y ago> something as simple as sleep Is sleep really considered simple?
- 3v1n0 6y agoC io APIs are sync, but there are so many that are not such thing. Potentially would even be possible to expose something like the io_uring async api to the browsers I guess.
- yxhuvud 6y agoWhile io_uring certainly is great, but it is a: Linux only. The main interest of browsers are Windows and Mac as most users are on those platforms. b: Limited to modern variants of the kernel - this is a greater problem the more features that is needed. Not everyone wants to be or can be a kernel hipster.
- flohofwoe 6y agoTo be fair, UI applications on most platforms that are not Windows or Linux have a very similar problem, you can't simply block the event loop for a few seconds or the whole UI will freeze and the OS will most likely terminate the application (on mobile at last). Usually one can workaround this with threads, alas, threading in the browser environment opens up a whole new can of worms. Asynchronous programming is a different coding mindset, and async-await provides a convenient hack/workaround/solution to go back to a simple linear execution flow (even if that's just an "illusion"). But this problem had been solved many decades ago on the OS level in UNIX and other multitasking operating systems already (and solved it much better, because async-await is essentially cooperative multitasking, like in Windows 3.x or classic MacOS).
- pjmlp 6y agoIf anything this article is an example how WebAssembly is miles behind of the alternatives avaible in 2011. Instead of just using Flash Editor with CrossBridge, here we are 10 years later doing low level plumbing into a standard that hardly moved past MVP 1.0 after 10 years. My favourite talk at Web Assembly 2020 Summit was about the possible failure for Web Assembly to gain wide adoption due to tooling constraints and minimal language support. This year, my favourite talk equates Web Assembly to the Concorde, that eventually was removed out of circulation, not due to the accident, but the running costs that did not justify high performance cross atlantic flying. So when will WebAssembly move beyond low level plumbing and compiler toolchains that require npm like dependencies to generate a plain .wasm file?
- TechBro8615 6y agoPersonally I'm more excited for WebAssembly on the server side. The possibilities for low-overhead multi-tenant workload sandboxing are fun to think about (CloudFlare is doing more than just think about them!).
- BiteCode_dev 6y agoYes, being able to compile my VueJS component from inside my Python VM would be a huge plus: I would finally have one single template language on the frontend and the backend, and just one endpoint for rendered pages and API.
- pjmlp 6y agoIt doesn't offer anything better than hundred other bytecode formats, some of them in use for decades, since IBM and Unisys mainframes have gotten into production.
- throwaway894345 6y agoWhat are your options if you want to support C, Go, Rust, Python (actual Python, not "Jython" or others with low ecosystem compatibility), and JavaScript? Of those bytecode formats that support those languages, which have something like Krustlet, which would allow us to leverage Kubernetes and its ecosystem?
- lights0123 6y agoThat article probably should have mentioned the existing code built into wasm-bindgen that allows cross-language async/await between Rust and JS.
- RReverser 6y ago(Author here - sorry, just noticed this post got to HN a few days ago.) True, I've considered describing that feature too, but in the end decided it would be too much deviation for the article that is already fairly large. That integration is very interesting on its own, but solves slightly different set of problems - that is, it can' t be used for bridging regular synchronous APIs like WASI in back-compat manner, but rather requires your entire stack to be built on top of async APIs. If it is, that's indeed an even better solution, but most likely at least majority of your dependencies just use regular std:: APIs that are sync-only. Describing those tradeoffs and doing meaningful comparison of two approaches feels like a whole separate blog post :)