simplify hierarchy of ResponseFuture (#791)

* simplify hierarchy of ResponseFuture

* dartfmt

* update changelog

---------

Co-authored-by: Moritz <mosum@google.com>
This commit is contained in:
Devon Carew 2025-06-24 09:59:04 -07:00 committed by GitHub
parent 79f277e7b9
commit c737e3d87e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 18 deletions

View File

@ -7,6 +7,8 @@
- Require package:http 1.4.0
- Require package:lints 6.0.0
- Require package:protobuf 4.1.0
- Simplify hierarchy of `ResponseFuture` (no longer have a private class in the
type hierarchy)
## 4.1.0

View File

@ -42,9 +42,7 @@ abstract class Response {
}
/// A gRPC response producing a single value.
class ResponseFuture<R> extends DelegatingFuture<R>
with _ResponseMixin<dynamic, R> {
@override
class ResponseFuture<R> extends DelegatingFuture<R> implements Response {
final ClientCall<dynamic, R> _call;
static R _ensureOnlyOneResponse<R>(R? previous, R element) {
@ -65,21 +63,25 @@ class ResponseFuture<R> extends DelegatingFuture<R>
.fold<R?>(null, _ensureOnlyOneResponse)
.then(_ensureOneResponse),
);
}
/// A gRPC response producing a stream of values.
class ResponseStream<R> extends StreamView<R> with _ResponseMixin<dynamic, R> {
@override
final ClientCall<dynamic, R> _call;
ResponseStream(this._call) : super(_call.response);
@override
ResponseFuture<R> get single => ResponseFuture(_call);
}
mixin _ResponseMixin<Q, R> implements Response {
ClientCall<Q, R> get _call;
@override
Future<Map<String, String>> get headers => _call.headers;
@override
Future<Map<String, String>> get trailers => _call.trailers;
@override
Future<void> cancel() => _call.cancel();
}
/// A gRPC response producing a stream of values.
class ResponseStream<R> extends StreamView<R> implements Response {
final ClientCall<dynamic, R> _call;
ResponseStream(this._call) : super(_call.response);
@override
ResponseFuture<R> get single => ResponseFuture(_call);
@override
Future<Map<String, String>> get headers => _call.headers;