Repository: tokio-rs/tokio
File: tokio/src/sync/watch.rs (Rust)

Code before:
    /// [`borrow`]: Receiver::borrow
    pub fn borrow_and_update(&mut self) -> Ref<'_, T> {
        let inner = self.shared.value.read();

        // After obtaining a read-lock no concurrent writes could occur
        // and the loaded version matches that of the borrowed reference.
        let new_version = self.shared.state.load().version();
        let has_changed = self.version != new_version;

        // Mark the shared value as seen by updating the version
        self.version = new_version;

        Ref { inner, has_changed }
    }

    /// Checks if this channel contains a message that this receiver has not yet
    /// seen. The current value will not be marked as seen.
    ///
    /// Although this method is called `has_changed`, it does not check
    /// messages for equality, so this call will return true even if the current
    /// message is equal to the previous message.
    ///
    /// # Errors
    ///
    /// Returns a [`RecvError`](error::RecvError) if and only if the channel has been closed.
    ///
    /// # Examples
    ///
    /// ## Basic usage
    /// ```
    /// use tokio::sync::watch;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let (tx, mut rx) = watch::channel("hello");
    ///
    ///     tx.send("goodbye").unwrap();
    ///
    ///     assert!(rx.has_changed().unwrap());
    ///     assert_eq!(*rx.borrow_and_update(), "goodbye");
    ///
    ///     // The value has been marked as seen
    ///     assert!(!rx.has_changed().unwrap());
    /// }
    /// ```
    ///
    /// ## Closed channel example
    /// ```
    /// use tokio::sync::watch;
    ///
    /// #[tokio::main]

Review comment (suggestion):
```suggestion
    /// Returns a [`RecvError`](error::RecvError) as long as the channel has been closed.
```

Code after:
    /// [`changed`]: Receiver::changed
    /// [`borrow`]: Receiver::borrow
    pub fn borrow_and_update(&mut self) -> Ref<'_, T> {
        let inner = self.shared.value.read();

        // After obtaining a read-lock no concurrent writes could occur
        // and the loaded version matches that of the borrowed reference.
        let new_version = self.shared.state.load().version();
        let has_changed = self.version != new_version;

        // Mark the shared value as seen by updating the version
        self.version = new_version;

        Ref { inner, has_changed }
    }

    /// Checks if this channel contains a message that this receiver has not yet
    /// seen. The current value will not be marked as seen.
    ///
    /// Although this method is called `has_changed`, it does not check
    /// messages for equality, so this call will return true even if the current
    /// message is equal to the previous message.
    ///
    /// # Errors
    ///
    /// Returns a [`RecvError`](error::RecvError) if and only if the channel has been closed.
    ///
    /// # Examples
    ///
    /// ## Basic usage
    ///
    /// ```
    /// use tokio::sync::watch;
    ///
    /// #[tokio::main]
    /// async fn main() {
    ///     let (tx, mut rx) = watch::channel("hello");
    ///
    ///     tx.send("goodbye").unwrap();
    ///
    ///     assert!(rx.has_changed().unwrap());
    ///     assert_eq!(*rx.borrow_and_update(), "goodbye");
    ///
    ///     // The value has been marked as seen
    ///     assert!(!rx.has_changed().unwrap());
    /// }
    /// ```
    ///
    /// ## Closed channel example
    ///
    /// ```