Skip to content

channel/recv: improving function docs and code example #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/sync/channel.rs
Original file line number Diff line number Diff line change
@@ -346,8 +346,9 @@ pub struct Receiver<T> {
impl<T> Receiver<T> {
/// Receives a message from the channel.
///
/// If the channel is empty and still has senders, this method will wait until a message is
/// sent into the channel or until all senders get dropped.
/// If the channel is emtpy and still has senders, this method
/// will wait until a message is sent into it. Once all senders
/// have been dropped it will return `None`.
///
/// # Examples
///
@@ -362,10 +363,13 @@ impl<T> Receiver<T> {
/// task::spawn(async move {
/// s.send(1).await;
/// s.send(2).await;
/// // Then we drop the sender
/// });
///
/// assert_eq!(r.recv().await, Some(1));
/// assert_eq!(r.recv().await, Some(2));
///
/// // recv() returns `None`
/// assert_eq!(r.recv().await, None);
/// #
/// # })