Skip to content
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

channel Receiver docs say it returns None when all senders have been dropped, but this is impossible #850

Closed
kellpossible opened this issue Aug 12, 2020 · 3 comments

Comments

@kellpossible
Copy link

https://docs.rs/async-std/1.6.2/async_std/sync/struct.Receiver.html#impl

Docs for recv():

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 it. Once all senders have been dropped it will return None.

How can it return None when the type signature is pub async fn recv<'_>(&'_ self) -> Result<T, RecvError>? It appears to be throwing an error instead, and an opaque error type too which makes it impossible to respond correctly to the specific situation where the senders were dropped vs some other kind of error condition.

This code triggers a panic on the last line panicked at 'The channel is empty.':

let (tx, rx) = async_std::sync::channel(10);
tx.send("hello").await;
drop(tx);
let msg = rx.recv().await.unwrap();
assert_eq!("hello", msg);
let result= rx.recv().await;
panic!(result.unwrap_err().to_string());
@kellpossible kellpossible changed the title Receiver docs say it returns None when all senders have been dropped, but this is impossible channel Receiver docs say it returns None when all senders have been dropped, but this is impossible Aug 12, 2020
@kellpossible
Copy link
Author

kellpossible commented Aug 13, 2020

The async-std book tutorial recommends using futures::channel::mpsc. What is the difference between this, and the async-std channel, and which should be preferred?

Edit:
I found some discussion here which talks about the differences #212

Perhaps the book examples should be updated to use async-std's channels?

@kellpossible
Copy link
Author

kellpossible commented Aug 13, 2020

It looks like this issue may be mostly solved by cd7fb9d

@yoshuawuyts
Copy link
Contributor

Closed by #827 which adds a new channel impl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants