Crate heph_inbox[−][src]
Expand description
Bounded capacity channel.
The channel is a multi-producer, single-consumer (MPSC) bounded queue. It is designed to be used as inbox for actors, following the actor model.
Notes
The implementation assumes the access to the channel is mostly uncontested and optimises for this use case. Furthermore it optimises for small memory footprint, sometimes over faster access.
The implementation doesn’t provide a lot of guarantees. For example this
channel is not guaranteed to be First In First Out (FIFO), it does this
on a best effort basis. In return it means that a slow Sender
does not
block the receiving of other messages.
Examples
Simple creation of a channel and sending a message over it.
use std::thread; use heph_inbox::RecvError; // Create a new small channel. let (sender, mut receiver) = heph_inbox::new_small(); 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::Empty) => continue, Err(RecvError::Disconnected) => break, } } }); sender_handle.join().unwrap(); receiver_handle.join().unwrap();
Modules
oneshot | One-shot channel. |
Structs
Id | Identifier of a channel. |
Manager | Manager of a channel. |
Receiver | Receiving side of the channel. |
ReceiverConnected | Error returned by |
RecvValue |
|
SendValue |
|
Sender | Sending side of the channel. |
Enums
RecvError | Error returned in case receiving a value from the channel fails. See
|
SendError | Error returned in case sending a value across the channel fails. See
|
Functions
new_small | Create a small bounded channel. |