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

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

Issue 882713009: Make synchronous broadcast StreamController throw if adding event while adding event. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update version number. Created 5 years, 10 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 | « pkg/async/test/stream_zip_zone_test.dart ('k') | sdk/lib/async/stream_controller.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 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 void _callOnCancel() { 330 void _callOnCancel() {
331 assert(_isEmpty); 331 assert(_isEmpty);
332 if (isClosed && _doneFuture._mayComplete) { 332 if (isClosed && _doneFuture._mayComplete) {
333 // When closed, _doneFuture is not null. 333 // When closed, _doneFuture is not null.
334 _doneFuture._asyncComplete(null); 334 _doneFuture._asyncComplete(null);
335 } 335 }
336 _runGuarded(_onCancel); 336 _runGuarded(_onCancel);
337 } 337 }
338 } 338 }
339 339
340 class _SyncBroadcastStreamController<T> extends _BroadcastStreamController<T> { 340 class _SyncBroadcastStreamController<T> extends _BroadcastStreamController<T>
341 implements SynchronousStreamController<T> {
341 _SyncBroadcastStreamController(void onListen(), void onCancel()) 342 _SyncBroadcastStreamController(void onListen(), void onCancel())
342 : super(onListen, onCancel); 343 : super(onListen, onCancel);
343 344
344 // EventDispatch interface. 345 // EventDispatch interface.
345 346
347 bool get _mayAddEvent => super._mayAddEvent && !_isFiring;
348
349 _addEventError() {
350 if (_isFiring) {
351 return new StateError(
352 "Cannot fire new event. Controller is already firing an event");
353 }
354 return super._addEventError();
355 }
356
346 void _sendData(T data) { 357 void _sendData(T data) {
347 if (_isEmpty) return; 358 if (_isEmpty) return;
348 if (_hasOneListener) { 359 if (_hasOneListener) {
349 _state |= _BroadcastStreamController._STATE_FIRING; 360 _state |= _BroadcastStreamController._STATE_FIRING;
350 _BroadcastSubscription subscription = _next; 361 _BroadcastSubscription subscription = _next;
351 subscription._add(data); 362 subscription._add(data);
352 _state &= ~_BroadcastStreamController._STATE_FIRING; 363 _state &= ~_BroadcastStreamController._STATE_FIRING;
353 if (_isEmpty) { 364 if (_isEmpty) {
354 _callOnCancel(); 365 _callOnCancel();
355 } 366 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 _pauseCount++; 514 _pauseCount++;
504 } 515 }
505 void resume() { _resume(null); } 516 void resume() { _resume(null); }
506 void _resume(_) { 517 void _resume(_) {
507 if (_pauseCount > 0) _pauseCount--; 518 if (_pauseCount > 0) _pauseCount--;
508 } 519 }
509 Future cancel() { return new _Future.immediate(null); } 520 Future cancel() { return new _Future.immediate(null); }
510 bool get isPaused => _pauseCount > 0; 521 bool get isPaused => _pauseCount > 0;
511 Future asFuture([Object value]) => new _Future(); 522 Future asFuture([Object value]) => new _Future();
512 } 523 }
OLDNEW
« no previous file with comments | « pkg/async/test/stream_zip_zone_test.dart ('k') | sdk/lib/async/stream_controller.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698