mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-17 00:00:11 +02:00
sync: add receiver_count to watch::Sender (#3729)
This commit is contained in:
@@ -417,6 +417,28 @@ impl<T> Sender<T> {
|
||||
Receiver::from_shared(version, shared)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the number of receivers that currently exist
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use tokio::sync::watch;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// let (tx, rx1) = watch::channel("hello");
|
||||
///
|
||||
/// assert_eq!(1, tx.receiver_count());
|
||||
///
|
||||
/// let mut _rx2 = rx1.clone();
|
||||
///
|
||||
/// assert_eq!(2, tx.receiver_count());
|
||||
/// }
|
||||
/// ```
|
||||
pub fn receiver_count(&self) -> usize {
|
||||
self.shared.ref_count_rx.load(Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for Sender<T> {
|
||||
|
||||
Reference in New Issue
Block a user