dicej / isyswasfa

I sync, you sync, we all sync for async!
39 stars 0 forks source link

could this work with `jco`? #1

Open DougAnderson444 opened 7 months ago

DougAnderson444 commented 7 months ago

Joel @dicej,

I need async in order to access IndexedDB from WIT component written in Rust but using jco.

Do you think this approach could work with jco? Any advice / thoughts on how that could look?

Thought I'd ask before attempting to dive in... I'm not really patient enough to wait for Preview 3 ;P

thanks!

dicej commented 7 months ago

Hi @DougAnderson444. To be clear: async works great in WASI 0.2.0 for components which are not composed with other components, and it also works great for composed components where only one of the subcomponents needs to do I/O at a time. If either of those apply to your use case, then isyswasfa is overkill. For reference, here's an example of a Rust component that uses a simple wasi:io/poll-based executor to do async I/O in a reasonably idiomatic way without any special host features: https://github.com/bytecodealliance/wasmtime/blob/main/crates/test-programs/src/bin/api_proxy_streaming.rs. See also https://blog.yoshuawuyts.com/building-an-async-runtime-for-wasi/ for an example of a more general-purpose executor based on WASI 0.2.0.

That said, if you really do need to compose components which do concurrent I/O, then porting isyswasfa to jco might make sense. I don't have experience with jco, nor do I have time to work on such a port, but if you're motivated you could look at the changes I made to wasmtime-wit-bindgen (in the wasmtime submodule in this repo), port them to jco, and then port https://github.com/dicej/isyswasfa/blob/main/host/src/lib.rs to jco as well. I'll confess I haven't made any effort to document that code, and chunks of it are completely untested -- it's all very much prototype-quality at this point and isn't necessarily designed for production use. Happy to answer any questions about it, though.