kawamuray / decaton-wasm-playground

Playground to play with experimental WebAssembly support for [Decaton](https://github.com/line/decaton)
2 stars 0 forks source link

Async sockets #1

Open hustxiaoc opened 3 years ago

hustxiaoc commented 3 years ago

Great work, any idea how to implement async sockets?

kawamuray commented 3 years ago

There should be various possible ways to do that.

I think the most straightforward approach is to add some APIs in WASI that provides similar functionality to Linux's non-blocking IO and select/epoll. Since most of the languages already has its own async runtime, just replacing the system calls layer that they're relying on, from unix/POSIX APIs to WASI would be the simplest and most efficient. In this case the things to do are to extend existing sockets APIs with non-blocking flag support and add a brand-new API for polling IO events from the host system.

Another approach would be attempting to provide richer APIs specialized for async IOs with a kind of runtime support. Some folks working on WASM/WASI seems to be preferring to give richer APIs support at WASI (so it does look something more than traditional unix's system call layer) and this approach might be worth it if many source languages gets library support to use unified async-IO layer provided by WASI. In this approach the things to do would be to add a newly designed APIs that might takes a callback (as a function reference) and call it upon completing requested I/O.