mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
sync: add watch::Sender::same_channel (#6637)
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user