Module heph_inbox::oneshot [−][src]
Expand description
One-shot channel.
The channel allows you to send a single value and that it. It does allow the
channel’s allocation to be reused via Receiver::try_reset
. It is
designed to be used for Remote Procedure Calls (RPC).
Examples
Simple creation of a channel and sending a message over it.
use std::thread; use heph_inbox::oneshot::{RecvError, new_oneshot}; // Create a new small channel. let (sender, mut receiver) = new_oneshot(); let sender_handle = thread::spawn(move || { if let Err(err) = sender.try_send("Hello world!".to_owned()) { panic!("Failed to send value: {}", err); } }); let receiver_handle = thread::spawn(move || { // NOTE: this is just an example don't actually use a loop like this, it // will waste CPU cycles when the channel is empty! loop { match receiver.try_recv() { Ok(value) => println!("Got a value: {}", value), Err(RecvError::NoValue) => continue, Err(RecvError::Disconnected) => break, } } }); sender_handle.join().unwrap(); receiver_handle.join().unwrap();
Structs
Receiver | The receiving half of the one-shot channel. |
RecvOnce |
|
RecvValue |
|
Sender | The sending half of the one-shot channel. |
Enums
RecvError | Error returned by |
Functions
new_oneshot | Create a new one-shot channel. |