Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Unified Diff: sdk/lib/async/stream_transformers.dart

Issue 2202533003: Return futures on Stream.cancel when possible. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove debug-print. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/async/stream_transformers.dart
diff --git a/sdk/lib/async/stream_transformers.dart b/sdk/lib/async/stream_transformers.dart
index e0982da4260ec621621a82b526aa21dac87f2be4..32fe28dfd820fab22c8b71e0099104cc59a28a89 100644
--- a/sdk/lib/async/stream_transformers.dart
+++ b/sdk/lib/async/stream_transformers.dart
@@ -33,6 +33,9 @@ class _SinkTransformerStreamSubscription<S, T>
/// The subscription to the input stream.
StreamSubscription<S> _subscription;
+ /// The cancelFuture (if any).
+ Future _cancelFuture;
Lasse Reichstein Nielsen 2016/08/01 15:23:26 Why a field? I only see it used inside one method?
floitsch 2016/08/01 21:00:37 Acknowledged.
+
_SinkTransformerStreamSubscription(Stream<S> source,
_SinkMapper<S, T> mapper,
void onData(T data),
@@ -109,9 +112,9 @@ class _SinkTransformerStreamSubscription<S, T>
if (_isSubscribed) {
StreamSubscription subscription = _subscription;
_subscription = null;
- subscription.cancel();
+ _cancelFuture = subscription.cancel();
Lasse Reichstein Nielsen 2016/08/01 15:23:26 That is, why is _cancelFuture not a local variable
floitsch 2016/08/01 15:55:55 In case someone calls `cancel` multiple times.
Lasse Reichstein Nielsen 2016/08/01 16:49:38 Possibly a good point. I'm not sure _onCancel will
floitsch 2016/08/01 21:00:37 You are right. Changed a bit more...
}
- return null;
+ return _cancelFuture ?? new Future.value(null);
}
void _handleData(S data) {

Powered by Google App Engine
This is Rietveld 408576698