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

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

Issue 15981003: Make new StreamController().isPaused be true until the first listener arrives. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | no next file » | 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 EventSink<T> get sink; 102 EventSink<T> get sink;
103 103
104 /** 104 /**
105 * Whether the stream is closed for adding more events. 105 * Whether the stream is closed for adding more events.
106 * 106 *
107 * If true, the "done" event might not have fired yet, but it has been 107 * If true, the "done" event might not have fired yet, but it has been
108 * scheduled, and it is too late to add more events. 108 * scheduled, and it is too late to add more events.
109 */ 109 */
110 bool get isClosed; 110 bool get isClosed;
111 111
112 /** Whether the subscription is active and paused. */ 112 /**
113 * Whether the subscription would need to buffer events.
114 *
115 * This is the case if the controller's stream has a listener and it is
116 * paused, or if it has not received a listener yet. In that case, the
117 * controller is considered paused as well.
118 *
119 * A broadcast stream controller is never considered paused. It always
120 * forwards its events to all uncanceled listeners, if any, and let them
121 * handle their own pausing.
122 */
113 bool get isPaused; 123 bool get isPaused;
114 124
115 /** Whether there is a subscriber on the [Stream]. */ 125 /** Whether there is a subscriber on the [Stream]. */
116 bool get hasListener; 126 bool get hasListener;
117 127
118 /** 128 /**
119 * Send or enqueue an error event. 129 * Send or enqueue an error event.
120 * 130 *
121 * Also allows an objection stack trace object, on top of what [EventSink] 131 * Also allows an objection stack trace object, on top of what [EventSink]
122 * allows. 132 * allows.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 184
175 /** 185 /**
176 * Whether a listener has existed and been cancelled. 186 * Whether a listener has existed and been cancelled.
177 * 187 *
178 * After this, adding more events will be ignored. 188 * After this, adding more events will be ignored.
179 */ 189 */
180 bool get _isCancelled => (_state & _STATE_CANCELLED) != 0; 190 bool get _isCancelled => (_state & _STATE_CANCELLED) != 0;
181 191
182 bool get isClosed => (_state & _STATE_CLOSED) != 0; 192 bool get isClosed => (_state & _STATE_CLOSED) != 0;
183 193
184 bool get isPaused => _subscription != null && _subscription._isInputPaused; 194 bool get isPaused => hasListener ? _subscription._isInputPaused
195 : !_isCancelled;
185 196
186 bool get hasListener => _subscription != null; 197 bool get hasListener => _subscription != null;
187 198
188 /** 199 /**
189 * Send or queue a data event. 200 * Send or queue a data event.
190 */ 201 */
191 void add(T value) { 202 void add(T value) {
192 if (isClosed) throw new StateError("Adding event after close"); 203 if (isClosed) throw new StateError("Adding event after close");
193 if (_subscription != null) { 204 if (_subscription != null) {
194 _subscription._add(value); 205 _subscription._add(value);
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 link = subscription._next; 558 link = subscription._next;
548 } 559 }
549 } 560 }
550 _state &= ~_STATE_FIRING; 561 _state &= ~_STATE_FIRING;
551 562
552 if (_isEmpty) { 563 if (_isEmpty) {
553 _runGuarded(_onCancel); 564 _runGuarded(_onCancel);
554 } 565 }
555 } 566 }
556 } 567 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698