diff --git a/src/lib.rs b/src/lib.rs index 245a216..3bdc944 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -493,6 +493,24 @@ impl Sender { channel: self.channel.clone(), } } + + /// Returns whether the senders belong to the same channel. + /// + /// # Examples + /// + /// ``` + /// # futures_lite::future::block_on(async { + /// use async_channel::unbounded; + /// + /// let (s, r) = unbounded::<()>(); + /// let s2 = s.clone(); + /// + /// assert!(s.same_channel(&s2)); + /// # }); + /// ``` + pub fn same_channel(&self, other: &Sender) -> bool { + Arc::ptr_eq(&self.channel, &other.channel) + } } impl Drop for Sender { @@ -820,6 +838,24 @@ impl Receiver { channel: self.channel.clone(), } } + + /// Returns whether the receivers belong to the same channel. + /// + /// # Examples + /// + /// ``` + /// # futures_lite::future::block_on(async { + /// use async_channel::unbounded; + /// + /// let (s, r) = unbounded::<()>(); + /// let r2 = r.clone(); + /// + /// assert!(r.same_channel(&r2)); + /// # }); + /// ``` + pub fn same_channel(&self, other: &Receiver) -> bool { + Arc::ptr_eq(&self.channel, &other.channel) + } } impl fmt::Debug for Receiver {