expression
Watch the latest state rather than every event
A watch channel shares the most recently published state with its receivers. Rapid updates may replace intermediate values before a receiver observes them. This is appropriate for configuration snapshots, not a complete audit history. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 2 false Common mistake: Using watch to deliver every individual payment or job event.
Formal Syntax & Structure
rust syntaxrust
tokio::sync::watch::channel(initial)Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { let (tx, mut rx) = tokio::sync::watch::channel(0); tx.send(1).unwrap(); tx.send(2).unwrap(); rx.changed().await.unwrap(); println!("{}", *rx.borrow()); println!("{}", rx.has_changed().unwrap());}