# tokio::sync::watch::channel - Rust
API documentation for the Rust `channel` fn in crate `tokio`.
Keywords: rust, rustlang, rust-lang, channel

# Function tokio::sync::watch::channel [−] [src]

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

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 rx.changed().await.is_ok() {
                println!("received = {:?}", *rx.borrow());
            }
        });

        tx.send("world")?;