Add onConnectionStateChanged on ClientConnection #563
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a callback on
ClientConnection
to get updates when theConnectionState
changes.Usage:
This is a first solution for issue #428. It's not perfect yet and could be improved upon, I'm open to critics/suggestions.
👀 Why is it important?
A modern app (particularly GUI) should be able to provide feedback to user related to the state of the connection. We don't want the user to wait until they interact to tell them that "oh actually the connection is down", we need to tell them as soon as possible.
🛠 Possible improvements
Maybe we could set that callback as a parameter of the
ClientChannel
? That way we wouldn't have to force the creation of the connection just to set it.Is the previous state necessary ? I put it there as I feel like it's important, going from
idle
toconnected
is not the same as going fromtransientFailure
toconnected
. But we could also leave that to the user to store the previous state 🤔