Struct tokio_stream::wrappers::WatchStream [−][src]
pub struct WatchStream<T> { /* fields omitted */ }
This is supported on crate feature
sync
only.Expand description
A wrapper around tokio::sync::watch::Receiver
that implements Stream
.
This stream will always start by yielding the current value when the WatchStream is polled, regardless of whether it was the initial value or sent afterwards.
Examples
use tokio_stream::{StreamExt, wrappers::WatchStream};
use tokio::sync::watch;
let (tx, rx) = watch::channel("hello");
let mut rx = WatchStream::new(rx);
assert_eq!(rx.next().await, Some("hello"));
tx.send("goodbye").unwrap();
assert_eq!(rx.next().await, Some("goodbye"));
use tokio_stream::{StreamExt, wrappers::WatchStream};
use tokio::sync::watch;
let (tx, rx) = watch::channel("hello");
let mut rx = WatchStream::new(rx);
tx.send("goodbye").unwrap();
assert_eq!(rx.next().await, Some("goodbye"));