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

Create 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

extern crate tokio;

use tokio::prelude::*;
use tokio::sync::watch;

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

tokio::spawn(rx.for_each(|value| {
    println!("received = {:?}", value);
    Ok(())
}).map_err(|_| ()));

tx.broadcast("world").unwrap();