Closed Ludonope closed 2 years ago
If this is merged then do not merge #565.
Thanks for contribution @Ludonope!
I think stream based API proposed by @Cobinja is more in line with Dart style (it also allows for multiple listeners out of the box, etc). Let's try to land #565 instead of this one.
Yeah makes more sense with stream!
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 🤔