Skip to content

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

Closed
@kellpossible

Description

@kellpossible

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions