Closed
Description
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());
Metadata
Metadata
Assignees
Labels
No labels