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

Side by Side Diff: sdk/lib/async/stream_controller.dart

Issue 50373003: Expose the cancelOnError in the StreamController.addStream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « no previous file | tests/lib/async/stream_controller_async_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // ------------------------------------------------------------------- 7 // -------------------------------------------------------------------
8 // Controller for creating and adding events to a stream. 8 // Controller for creating and adding events to a stream.
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 10
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 /** Whether there is a subscriber on the [Stream]. */ 160 /** Whether there is a subscriber on the [Stream]. */
161 bool get hasListener; 161 bool get hasListener;
162 162
163 /** 163 /**
164 * Send or enqueue an error event. 164 * Send or enqueue an error event.
165 * 165 *
166 * Also allows an objection stack trace object, on top of what [EventSink] 166 * Also allows an objection stack trace object, on top of what [EventSink]
167 * allows. 167 * allows.
168 */ 168 */
169 void addError(Object error, [StackTrace stackTrace]); 169 void addError(Object error, [StackTrace stackTrace]);
170
171 /**
172 * Receives events from [source] and puts them into this controller's stream.
173 *
174 * Returns a future which completes when the source stream is done.
175 *
176 * Events must not be added directly to this controller using [add],
177 * [addError], [close] or [addStream], until the returned future
178 * is complete.
179 *
180 * Data and error events are forwarded to this controller's stream. A done
181 * event on the source will end the `addStream` operation and complete the
182 * returned future.
183 *
184 * If [cancelOnError] is true, only the first error on [source] is
185 * forwarded to the controller's stream, and the `addStream` ends
186 * after this. If [cancelOnError] is false, all errors are forwarded
187 * and only a done event will end the `addStream`.
188 */
189 Future addStream(Stream<T> source, {bool cancelOnError: true});
170 } 190 }
171 191
172 192
173 abstract class _StreamControllerLifecycle<T> { 193 abstract class _StreamControllerLifecycle<T> {
174 StreamSubscription<T> _subscribe(bool cancelOnError); 194 StreamSubscription<T> _subscribe(bool cancelOnError);
175 void _recordPause(StreamSubscription<T> subscription) {} 195 void _recordPause(StreamSubscription<T> subscription) {}
176 void _recordResume(StreamSubscription<T> subscription) {} 196 void _recordResume(StreamSubscription<T> subscription) {}
177 Future _recordCancel(StreamSubscription<T> subscription) => null; 197 Future _recordCancel(StreamSubscription<T> subscription) => null;
178 } 198 }
179 199
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 */ 357 */
338 Error _badEventState() { 358 Error _badEventState() {
339 if (isClosed) { 359 if (isClosed) {
340 return new StateError("Cannot add event after closing"); 360 return new StateError("Cannot add event after closing");
341 } 361 }
342 assert(_isAddingStream); 362 assert(_isAddingStream);
343 return new StateError("Cannot add event while adding a stream"); 363 return new StateError("Cannot add event while adding a stream");
344 } 364 }
345 365
346 // StreamSink interface. 366 // StreamSink interface.
347 /**
348 * Receives events from [source] and puts them into this controller's stream.
349 *
350 * Returns a future which completes when the source stream is done.
351 *
352 * Events must not be added directly to this controller using [add],
353 * [addError], [close] or [addStream], until the returned future
354 * is complete.
355 *
356 * Data and error events are forwarded to this controller's stream. A done
357 * event on the source will end the `addStream` operation and complete the
358 * returned future.
359 *
360 * If [cancelOnError] is true, only the first error on [source] is
361 * forwarded to the controller's stream, and the `addStream` ends
362 * after this. If [cancelOnError] is false, all errors are forwarded
363 * and only a done event will end the `addStream`.
364 */
365 Future addStream(Stream<T> source, { bool cancelOnError: true }) { 367 Future addStream(Stream<T> source, { bool cancelOnError: true }) {
366 if (!_mayAddEvent) throw _badEventState(); 368 if (!_mayAddEvent) throw _badEventState();
367 if (_isCanceled) return new _Future.immediate(null); 369 if (_isCanceled) return new _Future.immediate(null);
368 _StreamControllerAddStreamState addState = 370 _StreamControllerAddStreamState addState =
369 new _StreamControllerAddStreamState(this, 371 new _StreamControllerAddStreamState(this,
370 _varData, 372 _varData,
371 source, 373 source,
372 cancelOnError); 374 cancelOnError);
373 _varData = addState; 375 _varData = addState;
374 _state |= _STATE_ADDSTREAM; 376 _state |= _STATE_ADDSTREAM;
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 _StreamControllerAddStreamState(_StreamController controller, 720 _StreamControllerAddStreamState(_StreamController controller,
719 this.varData, 721 this.varData,
720 Stream source, 722 Stream source,
721 bool cancelOnError) 723 bool cancelOnError)
722 : super(controller, source, cancelOnError) { 724 : super(controller, source, cancelOnError) {
723 if (controller.isPaused) { 725 if (controller.isPaused) {
724 addSubscription.pause(); 726 addSubscription.pause();
725 } 727 }
726 } 728 }
727 } 729 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/async/stream_controller_async_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698