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

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

Issue 18915008: Let StreamSubscription.cancel return a Future. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mark failing tests. Created 7 years, 2 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
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | tests/lib/async/stream_controller_async_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/stream_pipe.dart
diff --git a/sdk/lib/async/stream_pipe.dart b/sdk/lib/async/stream_pipe.dart
index cc0127ee50c9c36d892fd68744ba43005198e275..692deea8b396f054c50b4c3500e261360b8340a2 100644
--- a/sdk/lib/async/stream_pipe.dart
+++ b/sdk/lib/async/stream_pipe.dart
@@ -26,12 +26,35 @@ _runUserCode(userCode(),
}
}
-/** Helper function to make an onError argument to [_runUserCode]. */
-_cancelAndError(StreamSubscription subscription, _Future future) =>
- (error, StackTrace stackTrace) {
- subscription.cancel();
+/** Helper function to cancel a subscription and wait for the potential future,
+ before completing with an error. */
+void _cancelAndError(StreamSubscription subscription,
+ _Future future,
+ error,
+ StackTrace stackTrace) {
+ var cancelFuture = subscription.cancel();
+ if (cancelFuture is Future) {
+ cancelFuture.whenComplete(() => future._completeError(error, stackTrace));
+ } else {
future._completeError(error, stackTrace);
- };
+ }
+}
+
+/** Helper function to make an onError argument to [_runUserCode]. */
+_cancelAndErrorClosure(StreamSubscription subscription, _Future future) =>
+ ((error, StackTrace stackTrace) => _cancelAndError(
+ subscription, future, error, stackTrace));
+
+/** Helper function to cancel a subscription and wait for the potential future,
+ before completing with a value. */
+void _cancelAndValue(StreamSubscription subscription, _Future future, value) {
+ var cancelFuture = subscription.cancel();
+ if (cancelFuture is Future) {
+ cancelFuture.whenComplete(() => future._complete(value));
+ } else {
+ future._complete(value);
+ }
+}
/**
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | tests/lib/async/stream_controller_async_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698