Expand description
An async, lock-free, reusable channel for sending single values to asynchronous tasks.
In a multi-shot channel, the receiver half is reusable and able to recycle the sender half without ever re-allocating. Sending, polling and recycling the sender are all lock-free operations.
§Example
use std::thread;
async {
let (s, mut r) = multishot::channel();
// Send a value to the channel from another thread.
thread::spawn(move || {
s.send("42");
});
// Receive the value.
let res = r.recv().await;
assert_eq!(res, Ok("42"));
// Recycle the sender. This is guaranteed to succeed if the previous
// message has been read.
let s = r.sender().unwrap();
// Drop the sender on another thread without sending a message.
thread::spawn(move || {
drop(s);
});
// Receive an error.
let res = r.recv().await;
assert_eq!(res, Err(multishot::RecvError {}));
}
Structs§
- Receiver
- Reusable receiver of a multi-shot channel.
- Recv
- Future returned by
Receiver::recv()
. - Recv
Error - Error signaling that the sender was dropped without sending a value.
- Sender
- Single-use sender of a multi-shot channel.
Functions§
- channel
- Creates a new multi-shot channel.