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

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

Issue 301193010: Update documentation for "close". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests. Don't throw if listening on broadcast stream after close. Created 6 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 | « no previous file | sdk/lib/async/stream.dart » ('j') | sdk/lib/async/stream.dart » ('J')
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 class _BroadcastStream<T> extends _ControllerStream<T> { 7 class _BroadcastStream<T> extends _ControllerStream<T> {
8 _BroadcastStream(_StreamControllerLifecycle controller) : super(controller); 8 _BroadcastStream(_StreamControllerLifecycle controller) : super(controller);
9 9
10 bool get isBroadcast => true; 10 bool get isBroadcast => true;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 _BroadcastSubscriptionLink previous = subscription._previous; 173 _BroadcastSubscriptionLink previous = subscription._previous;
174 _BroadcastSubscriptionLink next = subscription._next; 174 _BroadcastSubscriptionLink next = subscription._next;
175 previous._next = next; 175 previous._next = next;
176 next._previous = previous; 176 next._previous = previous;
177 subscription._next = subscription._previous = subscription; 177 subscription._next = subscription._previous = subscription;
178 } 178 }
179 179
180 // _StreamControllerLifecycle interface. 180 // _StreamControllerLifecycle interface.
181 181
182 StreamSubscription<T> _subscribe(bool cancelOnError) { 182 StreamSubscription<T> _subscribe(bool cancelOnError) {
183 if (isClosed) {
184 throw new StateError("Subscribing to closed stream");
185 }
186 StreamSubscription subscription = 183 StreamSubscription subscription =
187 new _BroadcastSubscription<T>(this, cancelOnError); 184 new _BroadcastSubscription<T>(this, cancelOnError);
185 if (isClosed) {
186 subscription._addPending(const _DelayedDone());
187 return subscription;
188 }
188 _addListener(subscription); 189 _addListener(subscription);
189 if (identical(_next, _previous)) { 190 if (identical(_next, _previous)) {
190 // Only one listener, so it must be the first listener. 191 // Only one listener, so it must be the first listener.
191 _runGuarded(_onListen); 192 _runGuarded(_onListen);
192 } 193 }
193 return subscription; 194 return subscription;
194 } 195 }
195 196
196 Future _recordCancel(_BroadcastSubscription<T> subscription) { 197 Future _recordCancel(_BroadcastSubscription<T> subscription) {
197 // If already removed by the stream, don't remove it again. 198 // If already removed by the stream, don't remove it again.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 link = subscription._next; 307 link = subscription._next;
307 } 308 }
308 } 309 }
309 _state &= ~_STATE_FIRING; 310 _state &= ~_STATE_FIRING;
310 311
311 if (_isEmpty) { 312 if (_isEmpty) {
312 _callOnCancel(); 313 _callOnCancel();
313 } 314 }
314 } 315 }
315 316
316 void _callOnCancel() { 317 Future _callOnCancel() {
Anders Johnsen 2014/06/02 08:22:50 I see no return statements?
Lasse Reichstein Nielsen 2014/06/02 09:48:25 And I don't remember making this change. Odd.
317 assert(_isEmpty); 318 assert(_isEmpty);
318 if (isClosed && _doneFuture._mayComplete) { 319 if (isClosed && _doneFuture._mayComplete) {
319 // When closed, _doneFuture is not null. 320 // When closed, _doneFuture is not null.
320 _doneFuture._asyncComplete(null); 321 _doneFuture._asyncComplete(null);
321 } 322 }
322 _runGuarded(_onCancel); 323 _runGuarded(_onCancel);
323 } 324 }
324 } 325 }
325 326
326 class _SyncBroadcastStreamController<T> extends _BroadcastStreamController<T> { 327 class _SyncBroadcastStreamController<T> extends _BroadcastStreamController<T> {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 _pauseCount++; 489 _pauseCount++;
489 } 490 }
490 void resume() { _resume(null); } 491 void resume() { _resume(null); }
491 void _resume(_) { 492 void _resume(_) {
492 if (_pauseCount > 0) _pauseCount--; 493 if (_pauseCount > 0) _pauseCount--;
493 } 494 }
494 Future cancel() { return new _Future.immediate(null); } 495 Future cancel() { return new _Future.immediate(null); }
495 bool get isPaused => _pauseCount > 0; 496 bool get isPaused => _pauseCount > 0;
496 Future asFuture([Object value]) => new _Future(); 497 Future asFuture([Object value]) => new _Future();
497 } 498 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/async/stream.dart » ('j') | sdk/lib/async/stream.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698