Skip to content

Close vs disconnect in futures-channel #1346

Closed
@ghost

Description

I find the terminology around channel closing/disconnection in futures-channel confusing:

  • The documentation says a channel becomes disconnected when all its receivers or senders get dropped. However, a channel can also be manually closed. Those are two different operations, but the end result is the same: nothing can be sent into the channel anymore.

  • I'd prefer Receiver::close() to be named disconnect().

  • There's a similar method Sender::close_channel(). Why close_channel() and not just close() or disconnect()?

  • Why do we have Receiver::close(), but then also SendError::is_disconnected()? So if we call Receiver::close(), then we may get a SendError that reports the channel as being disconnected?

  • Similarly, if we drop all receivers and disconnect the channel, then Sender::is_closed() will return true.

I think we should pick either closed or disconnected and just stick with it. Between those two, disconnected is used in std::sync::mpsc, but closed is more common elsewhere (channels in Go get closed, Unix pipes get closed, etc.).

Finally, two more related questions:

  • Why is there Sender::is_closed() but not Receiver::is_closed()?

  • Why is SendError an opaque struct with is_* methods rather than an enum like std::sync::mpsc::TrySendError? Do we expect to add more error cases in the future?

Personally, I'm leaning towards universal terminology/API within the Rust ecosystem - it'd be great if we could make channel libraries (std::sync::mpsc, futures-channel, tokio-channel, crossbeam-channel) as similar and consistent as possible.

cc @cramertj

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions