kajacx / wasm-bridge

Provides a single unified API to run WASM modules on the desktop using wasmtime, or on the web using js-sys.
MIT License
47 stars 7 forks source link

Make js Store Sync #12

Closed kayhhh closed 6 months ago

kayhhh commented 8 months ago

Hi, I am trying to use this crate with Bevy, but cannot easily do so without Store being Sync. This is already the case with the wasmtime native build, but for the web build there is a Rc<RefCell<...>> causing issues.

I naively replaced it with Arc<RwLock<...>>, and while I'm not sure whether its correct to do so it let my code compile.

Awesome project by the way great work.

kayhhh commented 8 months ago

Well ended up getting a bit more complicated when I tried using WasiCtx within the Store type but I think thats working now too, by adding Sync to the streams.

kajacx commented 7 months ago

I am using this is a Bevy game too and ended up putting my store in an Arc Mutex, which works out too. But matching the Sync-ness of wasmtime's Store is probably a better idea, I will look into the PR next weekend.

kajacx commented 6 months ago

I have made Store Send and Sync in 0.3.2, and also in 0.4.0. Looking at the commits: @kayhhh replace LazyModuleMemory with Arc RwLock eca64d9 @kayhhh undo LazyModuleMemory Arc change I totally get it, I made it thread safe too until clippy explained to me that it's useless because ModuleMemory (which contains a JsValue) cannot be sent between threads anyway.