
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 nameddisconnect()
. -
There's a similar method
Sender::close_channel()
. Whyclose_channel()
and not justclose()
ordisconnect()
? -
Why do we have
Receiver::close()
, but then alsoSendError::is_disconnected()
? So if we callReceiver::close()
, then we may get aSendError
that reports the channel as being disconnected? -
Similarly, if we drop all receivers and disconnect the channel, then
Sender::is_closed()
will returntrue
.
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 notReceiver::is_closed()
? -
Why is
SendError
an opaque struct withis_*
methods rather than an enum likestd::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