Skip to content

Commit

Permalink
sync: add watch::Receiver::same_channel (#4581)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrens committed Mar 25, 2022
1 parent f84c4d5 commit a8b75db
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tokio/src/sync/watch.rs
Expand Up @@ -467,6 +467,22 @@ impl<T> Receiver<T> {
}
}

/// Returns `true` if receivers belong to the same channel.
///
/// # Examples
///
/// ```
/// let (tx, rx) = tokio::sync::watch::channel(true);
/// let rx2 = rx.clone();
/// assert!(rx.same_channel(&rx2));
///
/// let (tx3, rx3) = tokio::sync::watch::channel(true);
/// assert!(!rx3.same_channel(&rx2));
/// ```
pub fn same_channel(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.shared, &other.shared)
}

cfg_process_driver! {
pub(crate) fn try_has_changed(&mut self) -> Option<Result<(), error::RecvError>> {
maybe_changed(&self.shared, &mut self.version)
Expand Down

0 comments on commit a8b75db

Please sign in to comment.