Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add example to has_changed for error case
  • Loading branch information
DSharifi committed Sep 5, 2025
commit e6939dd32ef8e58c04912a4133e8911f4395004d
20 changes: 19 additions & 1 deletion tokio/src/sync/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ impl<T> Receiver<T> {
///
/// # Examples
///
/// ## Basic usage
/// ```
/// use tokio::sync::watch;
///
Expand All @@ -666,9 +667,26 @@ impl<T> Receiver<T> {
///
/// // The value has been marked as seen
/// assert!(!rx.has_changed().unwrap());
/// }
/// ```
///
/// ## Closed channel example
/// ```
/// use tokio::sync::watch;
///
/// #[tokio::main]
/// async fn main() {
/// let (tx, mut rx) = watch::channel("hello");
/// tx.send("goodbye").unwrap();
/// drop(tx);
/// // The `tx` handle has been dropped
///
/// // `has_changed` returns Ok(true) as the current value is not seen.
/// assert!(rx.has_changed().unwrap());
///
/// // Marks the current value as seen.
/// assert_eq!(*rx.borrow_and_update(), "goodbye");
///
/// // The `tx` handle has been dropped __AND__ the current value is seen.
/// assert!(rx.has_changed().is_err());
/// }
/// ```
Expand Down