pub fn channel<T: Clone>(init: T) -> (Sender<T>, Receiver<T>)
Expand description

Creates a new watch channel, returning the “send” and “receive” handles.

All values sent by Sender will become visible to the Receiver handles. Only the last value sent is made available to the Receiver half. All intermediate values are dropped.

Examples

use tokio::sync::watch;

    let (tx, mut rx) = watch::channel("hello");

    tokio::spawn(async move {
        while let Some(value) = rx.recv().await {
            println!("received = {:?}", value);
        }
    });

    tx.broadcast("world")?;