wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

`LocalShared` similar to `futures_util`'s `Shared`

Open andrewbaxter opened this issue 2 months ago • 2 comments

JsValue isn't Send/Sync since https://github.com/wasm-bindgen/wasm-bindgen/pull/955 . This prevents the use of OnceCell-like things and futures_util's Shared. I may hack up my own in the meantime, but would it make sense to have a similar LocalShared that can't be sent across threads?

I was trying to figure out the best place to ask about this:

  • wasm-bindgen has good reasons for making JsValue non sync/send, so probably not there
  • I was going to post in futures_util, but
  • it felt like LocalShared would parallel spawn_local which is here (edit: wasm-bindgen-futures) and not in tokio/futures

Edit: Oops, I thought wasm_bindgen_futures was a different repo and didn't notice.

andrewbaxter avatar Nov 03 '25 14:11 andrewbaxter

https://github.com/wasm-bindgen/wasm-bindgen/pull/4770 adds back Send and Sync support for JsValue with that configuration. Would that resolve your use case here?

guybedford avatar Nov 03 '25 21:11 guybedford

Oh yeah!

I'm working in the browser, where IIUC there may be multi-threaded environments at some point, so I think this may be riskier than having local-wrappers? But it'd work for me...

andrewbaxter avatar Nov 04 '25 02:11 andrewbaxter