Expand description
A multi-producer, single-consumer FIFO queue communication primitive.
This module provides message-based communication over channels, similar to std::sync::mpsc,
but designed to work reliably across Native and WebAssembly environments.
§Features
- Cross-Platform: Works on Native, WASM worker threads, and WASM main thread.
- Async Support: Provides
send_asyncandrecv_asyncfor integration with async runtimes. - Platform-Aware: Automatically chooses the best waiting strategy (blocking or spinning) based on the thread type.
- Infinite Buffer: The channel has an infinite buffer, so
sendnever blocks (unless the lock is contended).
§Usage
Create a channel with channel(), which returns a Sender and a Receiver.
use wasm_safe_thread::mpsc::channel;
let (tx, rx) = channel();
tx.send_sync(42).unwrap();
assert_eq!(rx.recv_sync().unwrap(), 42);Structs§
- Into
Iter - An iterator over messages from the receiver.
- Receiver
- The receiving half of the channel.
- Send
Error - An error returned from the
sendmethods. - Sender
- The sending half of the channel.
Enums§
- Recv
Error - An error returned from the
recvmethod. - Recv
Timeout Error - An error returned from the
recv_timeoutmethods. - TryRecv
Error - An error returned from the
try_recvmethod.
Functions§
- channel
- Creates a new asynchronous channel, returning the sender/receiver halves.