Skip to content

Commit

Permalink
Add example usage for fn same_channel in Sender and Receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Jul 29, 2024
1 parent 8184905 commit b6d906d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,19 @@ impl<T> Sender<T> {
}

/// 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<T>) -> bool {
Arc::ptr_eq(&self.channel, &other.channel)
}
Expand Down Expand Up @@ -827,6 +840,19 @@ impl<T> Receiver<T> {
}

/// 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<T>) -> bool {
Arc::ptr_eq(&self.channel, &other.channel)
}
Expand Down

0 comments on commit b6d906d

Please sign in to comment.