Skip to content

simplify hierarchy of ResponseFuture #791

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions lib/src/client/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -60,24 +58,30 @@ class ResponseFuture<R> extends DelegatingFuture<R>
}

ResponseFuture(this._call)
: super(_call.response
.fold<R?>(null, _ensureOnlyOneResponse)
.then(_ensureOneResponse));
: super(
_call.response
.fold<R?>(null, _ensureOnlyOneResponse)
.then(_ensureOneResponse),
);

@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> with _ResponseMixin<dynamic, R> {
@override
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);
}

mixin _ResponseMixin<Q, R> implements Response {
ClientCall<Q, R> get _call;

@override
Future<Map<String, String>> get headers => _call.headers;
Expand Down
Loading