Skip to content

Commit 74b2c74

Browse files
rklaehnnotgull
authored andcommitted
Add example usage for fn same_channel in Sender and Receiver
1 parent 681541a commit 74b2c74

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,19 @@ impl<T> Sender<T> {
495495
}
496496

497497
/// Returns whether the senders belong to the same channel.
498+
///
499+
/// # Examples
500+
///
501+
/// ```
502+
/// # futures_lite::future::block_on(async {
503+
/// use async_channel::unbounded;
504+
///
505+
/// let (s, r) = unbounded::<()>();
506+
/// let s2 = s.clone();
507+
///
508+
/// assert!(s.same_channel(&s2));
509+
/// # });
510+
/// ```
498511
pub fn same_channel(&self, other: &Sender<T>) -> bool {
499512
Arc::ptr_eq(&self.channel, &other.channel)
500513
}
@@ -827,6 +840,19 @@ impl<T> Receiver<T> {
827840
}
828841

829842
/// Returns whether the receivers belong to the same channel.
843+
///
844+
/// # Examples
845+
///
846+
/// ```
847+
/// # futures_lite::future::block_on(async {
848+
/// use async_channel::unbounded;
849+
///
850+
/// let (s, r) = unbounded::<()>();
851+
/// let r2 = r.clone();
852+
///
853+
/// assert!(r.same_channel(&r2));
854+
/// # });
855+
/// ```
830856
pub fn same_channel(&self, other: &Receiver<T>) -> bool {
831857
Arc::ptr_eq(&self.channel, &other.channel)
832858
}

0 commit comments

Comments
 (0)