oneshot-broadcast

Crates.iooneshot-broadcast
lib.rsoneshot-broadcast
version0.0.2
sourcesrc
created_at2024-01-21 22:59:42.663312
updated_at2024-01-22 00:10:42.648504
descriptionA oneshot-broadcast channel that broadcasts a value once without cloning it.
homepagehttps://github.com/jvdwrf/oneshot-broadcast
repositoryhttps://github.com/jvdwrf/oneshot-broadcast
max_upload_size
id1107944
size22,962
jasper (jvdwrf)

documentation

README

Crates.io Documentation

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(()));
}

Commit count: 0

cargo fmt