-
Notifications
You must be signed in to change notification settings - Fork 382
Unify APIs for Endpoint::closed, Connection::closed and Connection::on_closed #3959
Copy link
Copy link
Open
Labels
Milestone
Description
We have Connection::closed, Connection::on_closed and in the future we'll have an Endpoint::closed as well. All three work differently. We should unify them.
To detail what they do:
Connection::closedresolves toConnectionErroronce the connection is closed. The future is lifetime-bound toself, i.e. prevents the connection from being dropped (and thus close-on-drop) while the future is aliveConnection::on_closedresolves to(ConnectionError, ConnectionStats)once the connection is closed. The future is'staticand does not store a strong reference to the Connection, thus does not prevent the connection from being closed-on-drop when all other clones are dropped. We use this e.g. in the RemoteStateActor to get a notification once a connection is closed, but without keeping it alive while polling that future, which is what we want here.Endpoint::closed(to be added in the endpoint close PR) returns aCancellationToken, which does not keep the Endpoint alive, and can be used to resolve when the endpoint is closed, or to stop futures when the endpoint closes. I.e. it behaves likeConnection::on_closed, with the benefit of being a cancellation token, thus having some util methods (i.e.token.run_until_cancelled(fut))
I think since that was written, Endpoint::closed was changed to return a custom struct that implements Future.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
👍 Ready