2 releases
0.0.2 | Jan 22, 2024 |
---|---|
0.0.1 | Jan 21, 2024 |
#1392 in Asynchronous
23KB
563 lines
oneshot-broadcast
A oneshot-broadcast channel that broadcasts a value once without cloning the message.
Example
use oneshot_broadcast::*;
#[tokio::main]
async fn main() {
// Create the oneshot-broadcast channel
let (mut sender, mut receiver) = channel::<u32>();
// Send a message through the sender
sender.send(10);
// We can freely clone the receiver
let mut receiver2 = receiver.clone();
// and receive the message asynchronously.
assert_eq!(receiver.recv().await.unwrap(), &10);
assert_eq!(receiver2.recv().await.unwrap(), &10);
// Or, if we're sure that it's ready:
assert_eq!(receiver.get().unwrap().unwrap(), &10);
// As an extra feature, we can erase the receiver_type by
// turning it into a listener:
let listener /* : Listener */ = receiver.into_listener();
assert_eq!(listener.await, Ok(()));
}
Dependencies
~83KB