| OLD | NEW |
| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // so we don't bother calling it. | 60 // so we don't bother calling it. |
| 61 void _onPause() { } | 61 void _onPause() { } |
| 62 | 62 |
| 63 // The controller._recordResume doesn't do anything for a broadcast | 63 // The controller._recordResume doesn't do anything for a broadcast |
| 64 // controller, so we don't bother calling it. | 64 // controller, so we don't bother calling it. |
| 65 void _onResume() { } | 65 void _onResume() { } |
| 66 | 66 |
| 67 // _onCancel is inherited. | 67 // _onCancel is inherited. |
| 68 } | 68 } |
| 69 | 69 |
| 70 | |
| 71 abstract class _BroadcastStreamController<T> | 70 abstract class _BroadcastStreamController<T> |
| 72 implements StreamController<T>, | 71 implements StreamController<T>, |
| 73 _StreamControllerLifecycle<T>, | 72 _StreamControllerLifecycle<T>, |
| 74 _BroadcastSubscriptionLink, | 73 _BroadcastSubscriptionLink, |
| 75 _EventSink<T>, | 74 _EventSink<T>, |
| 76 _EventDispatch<T> { | 75 _EventDispatch<T> { |
| 77 static const int _STATE_INITIAL = 0; | 76 static const int _STATE_INITIAL = 0; |
| 78 static const int _STATE_EVENT_ID = 1; | 77 static const int _STATE_EVENT_ID = 1; |
| 79 static const int _STATE_FIRING = 2; | 78 static const int _STATE_FIRING = 2; |
| 80 static const int _STATE_CLOSED = 4; | 79 static const int _STATE_CLOSED = 4; |
| 81 static const int _STATE_ADDSTREAM = 8; | 80 static const int _STATE_ADDSTREAM = 8; |
| 82 | 81 |
| 83 final _NotificationHandler _onListen; | 82 _NotificationHandler _onListen; |
| 84 final _NotificationHandler _onCancel; | 83 _NotificationHandler _onCancel; |
| 85 | 84 |
| 86 // State of the controller. | 85 // State of the controller. |
| 87 int _state; | 86 int _state; |
| 88 | 87 |
| 89 // Double-linked list of active listeners. | 88 // Double-linked list of active listeners. |
| 90 _BroadcastSubscriptionLink _next; | 89 _BroadcastSubscriptionLink _next; |
| 91 _BroadcastSubscriptionLink _previous; | 90 _BroadcastSubscriptionLink _previous; |
| 92 | 91 |
| 93 // Extra state used during an [addStream] call. | 92 // Extra state used during an [addStream] call. |
| 94 _AddStreamState<T> _addStreamState; | 93 _AddStreamState<T> _addStreamState; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 106 * Any attempt to listen after calling [close] will throw, so there won't | 105 * Any attempt to listen after calling [close] will throw, so there won't |
| 107 * be any further listeners. | 106 * be any further listeners. |
| 108 */ | 107 */ |
| 109 _Future _doneFuture; | 108 _Future _doneFuture; |
| 110 | 109 |
| 111 _BroadcastStreamController(this._onListen, this._onCancel) | 110 _BroadcastStreamController(this._onListen, this._onCancel) |
| 112 : _state = _STATE_INITIAL { | 111 : _state = _STATE_INITIAL { |
| 113 _next = _previous = this; | 112 _next = _previous = this; |
| 114 } | 113 } |
| 115 | 114 |
| 115 void set onListen(void onListenHandler()) { _onListen = onListenHandler; } |
| 116 |
| 117 void set onPause(void onPauseHandler()) { |
| 118 throw new UnsupportedError( |
| 119 "Broadcast stream controllers do not support pause callbacks"); |
| 120 } |
| 121 |
| 122 void set onResume(void onResumeHandler()) { |
| 123 throw new UnsupportedError( |
| 124 "Broadcast stream controllers do not support pause callbacks"); |
| 125 } |
| 126 |
| 127 void set onCancel(onCancelHandler()) { _onCancel = onCancelHandler; } |
| 128 |
| 116 // StreamController interface. | 129 // StreamController interface. |
| 117 | 130 |
| 118 Stream<T> get stream => new _BroadcastStream<T>(this); | 131 Stream<T> get stream => new _BroadcastStream<T>(this); |
| 119 | 132 |
| 120 StreamSink<T> get sink => new _StreamSinkWrapper<T>(this); | 133 StreamSink<T> get sink => new _StreamSinkWrapper<T>(this); |
| 121 | 134 |
| 122 bool get isClosed => (_state & _STATE_CLOSED) != 0; | 135 bool get isClosed => (_state & _STATE_CLOSED) != 0; |
| 123 | 136 |
| 124 /** | 137 /** |
| 125 * A broadcast controller is never paused. | 138 * A broadcast controller is never paused. |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 _pauseCount++; | 527 _pauseCount++; |
| 515 } | 528 } |
| 516 void resume() { _resume(null); } | 529 void resume() { _resume(null); } |
| 517 void _resume(_) { | 530 void _resume(_) { |
| 518 if (_pauseCount > 0) _pauseCount--; | 531 if (_pauseCount > 0) _pauseCount--; |
| 519 } | 532 } |
| 520 Future cancel() { return new _Future.immediate(null); } | 533 Future cancel() { return new _Future.immediate(null); } |
| 521 bool get isPaused => _pauseCount > 0; | 534 bool get isPaused => _pauseCount > 0; |
| 522 Future asFuture([Object value]) => new _Future(); | 535 Future asFuture([Object value]) => new _Future(); |
| 523 } | 536 } |
| OLD | NEW |