Expand description
A minimal oneshot channel for synchronous Rust.
A oneshot channel is used for sending a single message between threads.
The channel function is used to create a Sender and Receiver
handle pair that form the channel.
- The
Senderhandle is used by the producer to send the value. - The
Receiverhandle is used by the consumer to receive the value.
Each handle can be used on other threads.
Sender::sendwill no block the calling thread.Receiver::recvwill block the calling thread.
§Example
let (tx, rx) = sync_oneshot::channel();
std::thread::spawn(move || {
std::thread::sleep(Duration::from_millis(200));
tx.send(5).unwrap();
});
// blocking thread until a message available
let val = rx.recv().unwrap();
assert_eq!(val, 5);Structs§
- Receiver
- Receive a value from the associated
Sender. - Recv
Error - Error returned by the
Receiver::recv. - Sender
- Sends a value to the associated
Receiver.
Enums§
- TryRecv
Error - Error returned by the
try_recvfunction onReceiver.
Functions§
- channel
- Creates a new oneshot channel, returning the sender/receiver halves.