Skip to content

Commit 3bf4f93

Browse files
authored
sync: add watch::Sender::same_channel (#6637)
1 parent 39cf6bb commit 3bf4f93

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tokio/src/sync/watch.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,22 @@ impl<T> Sender<T> {
13241324
pub fn receiver_count(&self) -> usize {
13251325
self.shared.ref_count_rx.load(Relaxed)
13261326
}
1327+
1328+
/// Returns `true` if senders belong to the same channel.
1329+
///
1330+
/// # Examples
1331+
///
1332+
/// ```
1333+
/// let (tx, rx) = tokio::sync::watch::channel(true);
1334+
/// let tx2 = tx.clone();
1335+
/// assert!(tx.same_channel(&tx2));
1336+
///
1337+
/// let (tx3, rx3) = tokio::sync::watch::channel(true);
1338+
/// assert!(!tx3.same_channel(&tx2));
1339+
/// ```
1340+
pub fn same_channel(&self, other: &Self) -> bool {
1341+
Arc::ptr_eq(&self.shared, &other.shared)
1342+
}
13271343
}
13281344

13291345
impl<T> Drop for Sender<T> {

0 commit comments

Comments
 (0)