Trying to use a std:;sync::mpsc::channel in wasm32-unknown-unknown on Chrome has resulted in panics.
This appears to be similar to the issue here sync-channels panicking · Issue #2406 · rustwasm/wasm-bindgen · GitHub ; which appears to claim that various sync primitives are not implemented on wasm32-unknown-unknown / browser.
Question: for aysnc rust on wasm32-unknown-unknown / browser, is there anything like channels ?
I ran into this same issue recently. In a pure wasm codebase, you can use
Rc<RefCell<VecDeque<T>>> or similar, but since I was adding wasm support to an existing codebase, I wanted to use mpsc for native and the latter for wasm. I ended up writing a wrapper to abstract between the two implementations, which wasn't too bad. I can post some of the code tonight. It's worth noting that
Receiver::recv_timeout has no possible implementation in wasm32-unknown-unknown without using Web APIs.
Edit: Oh right, another issue is that on wasm you'll have to go async since it's single-threaded (for now). The issue then with
Rc<RefCell<VecDeque<T>>> is you'd have to implement a simple
Waker strategy, so I ended up wrapping around
futures::channel::mpsc::unbounded instead, which happens to work on wasm32-unknown-unknown.
I'm pretty sure ordinary async channels from various crates should work. This includes the async-channel crate, but also the
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.