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:http 1.4.0
- Require package:lints 6.0.0 - Require package:lints 6.0.0
- Require package:protobuf 4.1.0 - Require package:protobuf 4.1.0
- Simplify hierarchy of `ResponseFuture` (no longer have a private class in the
type hierarchy)
## 4.1.0 ## 4.1.0

View File

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