Skip to content

Commit

Permalink
sync: add watch::Sender::same_channel (#6637)
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Jun 15, 2024
1 parent 39cf6bb commit 3bf4f93
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tokio/src/sync/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,22 @@ impl<T> Sender<T> {
pub fn receiver_count(&self) -> usize {
self.shared.ref_count_rx.load(Relaxed)
}

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

impl<T> Drop for Sender<T> {
Expand Down

0 comments on commit 3bf4f93

Please sign in to comment.