mirror of https://github.com/grpc/grpc-dart.git
Add a ChannelShutdownHandler callback (#620)
Add a way to react to the channel shutdown or termination with an optional callback. This is not necessarily the API which I would recommend, but this is the APi that was already inappropriately shipped and in use internally.
This commit is contained in:
parent
e8893cd08a
commit
a1a8e92e38
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -55,8 +55,10 @@ abstract class ClientChannelBase implements ClientChannel {
|
|||
bool _isShutdown = false;
|
||||
final StreamController<ConnectionState> _connectionStateStreamController =
|
||||
StreamController.broadcast();
|
||||
final void Function()? _channelShutdownHandler;
|
||||
|
||||
ClientChannelBase();
|
||||
ClientChannelBase({void Function()? channelShutdownHandler})
|
||||
: _channelShutdownHandler = channelShutdownHandler;
|
||||
|
||||
@override
|
||||
Future<void> 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();
|
||||
|
|
|
|||
|
|
@ -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() =>
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue