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

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

Issue 14237002: Add StreamSubscription.asFuture. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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_impl.dart
diff --git a/sdk/lib/async/stream_impl.dart b/sdk/lib/async/stream_impl.dart
index e6de3d7dc38c073531119041c2bbee913ef0cfc0..fd7d7db3a8e5b59d0f9239a8258a77e4a68c5296 100644
--- a/sdk/lib/async/stream_impl.dart
+++ b/sdk/lib/async/stream_impl.dart
@@ -955,6 +955,19 @@ class _StreamSubscriptionImpl<T> extends _StreamListener<T>
if (!_isSubscribed || !isPaused) return;
_source._resume(this, false);
}
+
+ Future asFuture([var futureValue]) {
+ _FutureImpl<T> result = new _FutureImpl<T>();
+
+ // Overwrite the onDone and onError handlers.
+ onDone(() { result._setValue(futureValue); });
+ onError((AsyncError error) {
+ cancel();
Anders Johnsen 2013/04/15 09:15:47 Set unsubscribeOnError = true?
Lasse Reichstein Nielsen 2013/04/15 10:19:15 It's final, and if you overwrite onError again, wh
+ result._setError(error);
+ });
+
+ return result;
+ }
}
// Internal helpers.

Powered by Google App Engine
This is Rietveld 408576698