-
Notifications
You must be signed in to change notification settings - Fork 631
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
Close vs disconnect in futures-channel #1346
Comments
Not sure how accurate this information is now that #1443 has been merged. The PR introduces a |
I would be in favor of using If we don't want to distinguish between disconnect and close, I don't think this feature can work. However, personally I find it questionable. I wonder if anyone really uses this. I would suggest that one drops all senders in order to close a channel. Otherwise only a specific sender is closed. I even wonder about the usefulness of the |
I'd love to see docs improved to clarify the situation if any of y'all want to send a PR! Otherwise, there hasn't been much discussion on this issue so I'm going to close for now. |
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
The text was updated successfully, but these errors were encountered: