diff options
Diffstat (limited to 'tokio/src/sync/mpsc/bounded.rs')
-rw-r--r-- | tokio/src/sync/mpsc/bounded.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tokio/src/sync/mpsc/bounded.rs b/tokio/src/sync/mpsc/bounded.rs index 542eae27..5e94e729 100644 --- a/tokio/src/sync/mpsc/bounded.rs +++ b/tokio/src/sync/mpsc/bounded.rs @@ -523,6 +523,28 @@ impl<T> Sender<T> { enter_handle.block_on(self.send(value)).unwrap() } + /// Checks if the channel has been closed. This happens when the + /// [`Receiver`] is dropped, or when the [`Receiver::close`] method is + /// called. + /// + /// [`Receiver`]: crate::sync::mpsc::Receiver + /// [`Receiver::close`]: crate::sync::mpsc::Receiver::close + /// + /// ``` + /// let (tx, rx) = tokio::sync::mpsc::channel::<()>(42); + /// assert!(!tx.is_closed()); + /// + /// let tx2 = tx.clone(); + /// assert!(!tx2.is_closed()); + /// + /// drop(rx); + /// assert!(tx.is_closed()); + /// assert!(tx2.is_closed()); + /// ``` + pub fn is_closed(&self) -> bool { + self.chan.is_closed() + } + /// Wait for channel capacity. Once capacity to send one message is /// available, it is reserved for the caller. /// |