Skip to content
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

Expose onConnectionStateChanged for channels #565

Merged
merged 6 commits into from
Aug 15, 2022

Conversation

Cobinja
Copy link
Contributor

@Cobinja Cobinja commented Jun 26, 2022

This offers a Stream on channels. Only for Http2Channel, not for web usage.

Usage:
clientChannel.onConnectionStateChanged.listen(...)

This is an alternative to #563. Only merge one of these.

This offers a Stream<ConnectionState> on channels. Only for Http2Channel, not for web usage.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 26, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Cobinja / name: Cobinja (1768b82)

@Cobinja Cobinja changed the title Expose onConnectionChanged for channels Expose onConnectionStateChanged for channels Jun 26, 2022
lib/src/client/http2_channel.dart Outdated Show resolved Hide resolved
lib/src/client/channel.dart Outdated Show resolved Hide resolved
@@ -31,27 +33,89 @@ class ClientChannel extends ClientChannelBase {
final Object host;
final int port;
final ChannelOptions options;
final StreamController<ConnectionState> connectionStateStreamController =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this live in ClientChannelBase instead? Then you don't need any of the duplicated code below.

You would need to add a member to ClientChannel though to expose state changes in some form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in the new commit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion was to move all of the code to the base class (this includes code from terminate and shutdown as well as attaching status change callback to the connection object).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, I didn't catch that from the previous comments. I'll do it it tonight after work at my dayjob.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No rush.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think moving everything to ClientChannelBase is the best way to go. The callback to the connection object has to stay because it's specific to http2 compared to web channels which don't have the ability to track state changes in the first place.
I'm also removing the stream getter override in the web channel, so that devs don't have to catch any exception, the stream will just do nothing (that noop is documented).

Cobinja added 2 commits June 27, 2022 11:15
- improve documentation wording
- use whenComplete instead of then when closing the stream sink
@Cobinja Cobinja requested a review from mraleph June 28, 2022 18:11
Copy link
Member

@mraleph mraleph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change version number in pubspec.yaml to 3.1.0-dev and add corresponding CHANGELOG.md entry describing the change.

lib/src/client/channel.dart Show resolved Hide resolved
lib/src/client/http2_connection.dart Outdated Show resolved Hide resolved
- changed version to 3.1.0-dev
- Added changelog entry
- moved definition of onStateChanged to ClientConnection as a setter
@Cobinja Cobinja requested a review from mraleph July 1, 2022 10:45
@mraleph
Copy link
Member

mraleph commented Jul 1, 2022

Thanks @Cobinja. I think this is good to go. I have refactored things a bit more (you introduced the field I asked for - but did not actually make use of it to share repeating code). You can take a look at the final version.

@Cobinja
Copy link
Contributor Author

Cobinja commented Jul 1, 2022

My thought process was "Web channels might need a completely different implementation, so just provide the common API". I'm fine with your changes.

@andreadaoud
Copy link

Hi,

Just a ping on this PR. What's blocking this from being merged?

@natebosch
Copy link
Contributor

This was a breaking change - there are internal implementations of ClientConnection which are broken because they no longer implement the entire interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants