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

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

Issue 1177343004: Add Stream.empty. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Remove the null future "optimization". Fix some missing type parameters. Created 5 years, 6 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
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | sdk/lib/async/stream_impl.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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 * [onResume] call might not be executed. 73 * [onResume] call might not be executed.
74 */ 74 */
75 factory StreamController({void onListen(), 75 factory StreamController({void onListen(),
76 void onPause(), 76 void onPause(),
77 void onResume(), 77 void onResume(),
78 onCancel(), 78 onCancel(),
79 bool sync: false}) { 79 bool sync: false}) {
80 if (onListen == null && onPause == null && 80 if (onListen == null && onPause == null &&
81 onResume == null && onCancel == null) { 81 onResume == null && onCancel == null) {
82 return sync 82 return sync
83 ? new _NoCallbackSyncStreamController/*<T>*/() 83 ? new _NoCallbackSyncStreamController<T>()
84 : new _NoCallbackAsyncStreamController/*<T>*/(); 84 : new _NoCallbackAsyncStreamController<T>();
85 } 85 }
86 return sync 86 return sync
87 ? new _SyncStreamController<T>(onListen, onPause, onResume, onCancel) 87 ? new _SyncStreamController<T>(onListen, onPause, onResume, onCancel)
88 : new _AsyncStreamController<T>(onListen, onPause, onResume, onCancel); 88 : new _AsyncStreamController<T>(onListen, onPause, onResume, onCancel);
89 } 89 }
90 90
91 /** 91 /**
92 * A controller where [stream] can be listened to more than once. 92 * A controller where [stream] can be listened to more than once.
93 * 93 *
94 * The [Stream] returned by [stream] is a broadcast stream. 94 * The [Stream] returned by [stream] is a broadcast stream.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 */ 169 */
170 bool get isPaused; 170 bool get isPaused;
171 171
172 /** Whether there is a subscriber on the [Stream]. */ 172 /** Whether there is a subscriber on the [Stream]. */
173 bool get hasListener; 173 bool get hasListener;
174 174
175 /** 175 /**
176 * Send or enqueue an error event. 176 * Send or enqueue an error event.
177 * 177 *
178 * If [error] is `null`, it is replaced by a [NullThrownError]. 178 * If [error] is `null`, it is replaced by a [NullThrownError].
179 *
180 * Also allows an objection stack trace object, on top of what [EventSink]
181 * allows.
182 */ 179 */
183 void addError(Object error, [StackTrace stackTrace]); 180 void addError(Object error, [StackTrace stackTrace]);
184 181
185 /** 182 /**
186 * Receives events from [source] and puts them into this controller's stream. 183 * Receives events from [source] and puts them into this controller's stream.
187 * 184 *
188 * Returns a future which completes when the source stream is done. 185 * Returns a future which completes when the source stream is done.
189 * 186 *
190 * Events must not be added directly to this controller using [add], 187 * Events must not be added directly to this controller using [add],
191 * [addError], [close] or [addStream], until the returned future 188 * [addError], [close] or [addStream], until the returned future
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 _Future _doneFuture; 384 _Future _doneFuture;
388 385
389 _StreamController(); 386 _StreamController();
390 387
391 _NotificationHandler get _onListen; 388 _NotificationHandler get _onListen;
392 _NotificationHandler get _onPause; 389 _NotificationHandler get _onPause;
393 _NotificationHandler get _onResume; 390 _NotificationHandler get _onResume;
394 _NotificationHandler get _onCancel; 391 _NotificationHandler get _onCancel;
395 392
396 // Return a new stream every time. The streams are equal, but not identical. 393 // Return a new stream every time. The streams are equal, but not identical.
397 Stream<T> get stream => new _ControllerStream(this); 394 Stream<T> get stream => new _ControllerStream<T>(this);
398 395
399 /** 396 /**
400 * Returns a view of this object that only exposes the [StreamSink] interface. 397 * Returns a view of this object that only exposes the [StreamSink] interface.
401 */ 398 */
402 StreamSink<T> get sink => new _StreamSinkWrapper<T>(this); 399 StreamSink<T> get sink => new _StreamSinkWrapper<T>(this);
403 400
404 /** 401 /**
405 * Whether a listener has existed and been canceled. 402 * Whether a listener has existed and been canceled.
406 * 403 *
407 * After this, adding more events will be ignored. 404 * After this, adding more events will be ignored.
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 this._onCancel()); 748 this._onCancel());
752 } 749 }
753 750
754 abstract class _NoCallbacks { 751 abstract class _NoCallbacks {
755 _NotificationHandler get _onListen => null; 752 _NotificationHandler get _onListen => null;
756 _NotificationHandler get _onPause => null; 753 _NotificationHandler get _onPause => null;
757 _NotificationHandler get _onResume => null; 754 _NotificationHandler get _onResume => null;
758 _NotificationHandler get _onCancel => null; 755 _NotificationHandler get _onCancel => null;
759 } 756 }
760 757
761 class _NoCallbackAsyncStreamController/*<T>*/ = _StreamController/*<T>*/ 758 class _NoCallbackAsyncStreamController<T> = _StreamController<T>
762 with _AsyncStreamControllerDispatch/*<T>*/, _NoCallbacks; 759 with _AsyncStreamControllerDispatch<T>, _NoCallbacks;
763 760
764 class _NoCallbackSyncStreamController/*<T>*/ = _StreamController/*<T>*/ 761 class _NoCallbackSyncStreamController<T> = _StreamController<T>
765 with _SyncStreamControllerDispatch/*<T>*/, _NoCallbacks; 762 with _SyncStreamControllerDispatch<T>, _NoCallbacks;
766 763
767 typedef _NotificationHandler(); 764 typedef _NotificationHandler();
768 765
769 Future _runGuarded(_NotificationHandler notificationHandler) { 766 Future _runGuarded(_NotificationHandler notificationHandler) {
770 if (notificationHandler == null) return null; 767 if (notificationHandler == null) return null;
771 try { 768 try {
772 var result = notificationHandler(); 769 var result = notificationHandler();
773 if (result is Future) return result; 770 if (result is Future) return result;
774 return null; 771 return null;
775 } catch (e, s) { 772 } catch (e, s) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 _StreamControllerAddStreamState(_StreamController controller, 899 _StreamControllerAddStreamState(_StreamController controller,
903 this.varData, 900 this.varData,
904 Stream source, 901 Stream source,
905 bool cancelOnError) 902 bool cancelOnError)
906 : super(controller, source, cancelOnError) { 903 : super(controller, source, cancelOnError) {
907 if (controller.isPaused) { 904 if (controller.isPaused) {
908 addSubscription.pause(); 905 addSubscription.pause();
909 } 906 }
910 } 907 }
911 } 908 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | sdk/lib/async/stream_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698