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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.async; 5 part of dart.async;
6 6
7 /** Utility function to create an [AsyncError] if [error] isn't one already. */ 7 /** Utility function to create an [AsyncError] if [error] isn't one already. */
8 AsyncError _asyncError(Object error, Object stackTrace, [AsyncError cause]) { 8 AsyncError _asyncError(Object error, Object stackTrace, [AsyncError cause]) {
9 if (error is AsyncError) return error; 9 if (error is AsyncError) return error;
10 if (cause == null) return new AsyncError(error, stackTrace); 10 if (cause == null) return new AsyncError(error, stackTrace);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 void onDone(void handleDone()) { 124 void onDone(void handleDone()) {
125 if (handleDone == null) handleDone = _nullDoneHandler; 125 if (handleDone == null) handleDone = _nullDoneHandler;
126 _onDone = handleDone; 126 _onDone = handleDone;
127 } 127 }
128 128
129 void pause([Future resumeSignal]); 129 void pause([Future resumeSignal]);
130 130
131 void resume(); 131 void resume();
132 132
133 void cancel(); 133 void cancel();
134
135 Future asFuture([var futureValue]) {
136 _FutureImpl<T> result = new _FutureImpl<T>();
137
138 // Overwrite the onDone and onError handlers.
139 onDone(() { result._setValue(futureValue); });
140 onError((AsyncError error) {
141 cancel();
142 result._setError(error);
143 });
144
145 return result;
146 }
134 } 147 }
135 148
136 149
137 /** 150 /**
138 * Abstract superclass for subscriptions that forward to other subscriptions. 151 * Abstract superclass for subscriptions that forward to other subscriptions.
139 */ 152 */
140 class _ForwardingStreamSubscription<S, T> 153 class _ForwardingStreamSubscription<S, T>
141 extends _BaseStreamSubscription<T> implements _EventOutputSink<T> { 154 extends _BaseStreamSubscription<T> implements _EventOutputSink<T> {
142 final _ForwardingStream<S, T> _stream; 155 final _ForwardingStream<S, T> _stream;
143 final bool _unsubscribeOnError; 156 final bool _unsubscribeOnError;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 528
516 void handleError(AsyncError error, EventSink<T> sink) { 529 void handleError(AsyncError error, EventSink<T> sink) {
517 _handleError(error, sink); 530 _handleError(error, sink);
518 } 531 }
519 532
520 void handleDone(EventSink<T> sink) { 533 void handleDone(EventSink<T> sink) {
521 _handleDone(sink); 534 _handleDone(sink);
522 } 535 }
523 } 536 }
524 537
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698