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

Unified Diff: sdk/lib/async/stream_pipe.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_pipe.dart
diff --git a/sdk/lib/async/stream_pipe.dart b/sdk/lib/async/stream_pipe.dart
index aa3da2a664aebfb6506a985d95b7aa040c2c234c..1ec11194156813be9c4d0df26bb4127cee03ae74 100644
--- a/sdk/lib/async/stream_pipe.dart
+++ b/sdk/lib/async/stream_pipe.dart
@@ -131,6 +131,19 @@ abstract class _BaseStreamSubscription<T> implements StreamSubscription<T> {
void resume();
void cancel();
+
+ Future asFuture([var futureValue]) {
+ _FutureImpl<T> result = new _FutureImpl<T>();
+
+ // Overwrite the onDone and onError handlers.
+ onDone(() { result._setValue(futureValue); });
+ onError((AsyncError error) {
+ cancel();
+ result._setError(error);
+ });
+
+ return result;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698