wapc / wapc-rs

waPC Rust monorepo
Apache License 2.0
74 stars 9 forks source link

`WapcHost` usage in async contexts #92

Open muse254 opened 1 month ago

muse254 commented 1 month ago

I'd like to request for WapcHost to have another implementation that can be used in async environments by the caller. I'm aware that execution of WebAssembly modules is single threaded.

No amount of ceremony helped sidestep this issue. Also redoing the implementation in project doesn't work because of private fields/methods accessed.

Here's what I settled for reference: https://github.com/muse254/wapc-rs/pull/1/files

The error related to this: (self holds WapcHost in it's fields)

error: future cannot be sent between threads safely
  --> harness-node/src/main.rs:50:5
   |
50 | /     pub(crate) async fn handler(
51 | |         &mut self,
52 | |         req: Request,
53 | |     ) -> HarnessResult<Response<Cursor<Vec<u8>>>> {
   | |_________________________________________________^
   |
   = note: `(dyn wapc::wapchost::traits::WebAssemblyEngineProvider + 'static)` doesn't implement `std::marker::Send`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#future_not_send
flavio commented 1 month ago

@muse254 that's super nice. This is something I wanted to implement since a long time. I'll take a look at the drafted PR during this week.

flavio commented 1 month ago

I looked into your draft PR, then I started working on the topic during the weekend.

The amount of changes to be done was massive. Everything seems to be working 😀 I’m going to open a PR in the next days

muse254 commented 1 month ago

I'll be looking forward to the next release. Thank you for the fast turnaround.

flavio commented 1 month ago

@muse254 take a look at the linked PR and let me know what do you think about it. I've also added examples

muse254 commented 1 month ago

Hey, it looks really fleshed out. I'll be trying it out to see if I have any issues to report

muse254 commented 1 month ago

@flavio I've done some initial tests, and everything seems to be working well, at least for my use cases with WapcHostAsync and related functionality. I'm okay with the implementation as it is. Thanks again for the quick turnaround!

muse254 commented 1 week ago

Hey, how's the review coming along. Saw that it's stale. @flavio

flavio commented 1 week ago

@muse254 I've pinged the other waPC maintainers on https://github.com/wapc/wapc-rs/pull/96