diff --git a/CHANGELOG.md b/CHANGELOG.md index 100af45..4d622da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.1.1-dev +## 3.2.0-dev * `ChannelOptions` now exposes `connectTimeout`, which is used on the socket connect. This is used to specify the maximum allowed time to wait @@ -8,6 +8,8 @@ * Require Dart 2.17 or greater. * Fix issue [#51](https://github.com/grpc/grpc-dart/issues/51), add support for custom error handling. * Expose client IP address to server +* Add a `channelShutdownHandler` argument to `ClientChannel` and the subclasses. + This callback can be used to react to channel shutdown or termination. ## 3.1.0 diff --git a/lib/src/client/channel.dart b/lib/src/client/channel.dart index f7de79e..bbc1461 100644 --- a/lib/src/client/channel.dart +++ b/lib/src/client/channel.dart @@ -55,8 +55,10 @@ abstract class ClientChannelBase implements ClientChannel { bool _isShutdown = false; final StreamController _connectionStateStreamController = StreamController.broadcast(); + final void Function()? _channelShutdownHandler; - ClientChannelBase(); + ClientChannelBase({void Function()? channelShutdownHandler}) + : _channelShutdownHandler = channelShutdownHandler; @override Future shutdown() async { @@ -66,6 +68,7 @@ abstract class ClientChannelBase implements ClientChannel { await _connection.shutdown(); await _connectionStateStreamController.close(); } + _channelShutdownHandler?.call(); } @override @@ -75,6 +78,7 @@ abstract class ClientChannelBase implements ClientChannel { await _connection.terminate(); await _connectionStateStreamController.close(); } + _channelShutdownHandler?.call(); } ClientConnection createConnection(); diff --git a/lib/src/client/http2_channel.dart b/lib/src/client/http2_channel.dart index 9326766..2657eb0 100644 --- a/lib/src/client/http2_channel.dart +++ b/lib/src/client/http2_channel.dart @@ -32,9 +32,12 @@ class ClientChannel extends ClientChannelBase { final int port; final ChannelOptions options; - ClientChannel(this.host, - {this.port = 443, this.options = const ChannelOptions()}) - : super(); + ClientChannel( + this.host, { + this.port = 443, + this.options = const ChannelOptions(), + super.channelShutdownHandler, + }); @override ClientConnection createConnection() => diff --git a/lib/src/client/web_channel.dart b/lib/src/client/web_channel.dart index f81da14..c53fe90 100644 --- a/lib/src/client/web_channel.dart +++ b/lib/src/client/web_channel.dart @@ -21,7 +21,7 @@ import 'transport/xhr_transport.dart'; class GrpcWebClientChannel extends ClientChannelBase { final Uri uri; - GrpcWebClientChannel.xhr(this.uri) : super(); + GrpcWebClientChannel.xhr(this.uri, {super.channelShutdownHandler}); @override ClientConnection createConnection() { diff --git a/pubspec.yaml b/pubspec.yaml index e85b06b..9fab7fa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: grpc description: Dart implementation of gRPC, a high performance, open-source universal RPC framework. -version: 3.1.1-dev +version: 3.2.0-dev repository: https://github.com/grpc/grpc-dart