| 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 11 matching lines...) Expand all Loading... |
| 22 static const int _STATE_REMOVE_AFTER_FIRING = 4; | 22 static const int _STATE_REMOVE_AFTER_FIRING = 4; |
| 23 // TODO(lrn): Use the _state field on _ControllerSubscription to | 23 // TODO(lrn): Use the _state field on _ControllerSubscription to |
| 24 // also store this state. Requires that the subscription implementation | 24 // also store this state. Requires that the subscription implementation |
| 25 // does not assume that it's use of the state integer is the only use. | 25 // does not assume that it's use of the state integer is the only use. |
| 26 int _eventState; | 26 int _eventState; |
| 27 | 27 |
| 28 _BroadcastSubscriptionLink _next; | 28 _BroadcastSubscriptionLink _next; |
| 29 _BroadcastSubscriptionLink _previous; | 29 _BroadcastSubscriptionLink _previous; |
| 30 | 30 |
| 31 _BroadcastSubscription(_StreamControllerLifecycle controller, | 31 _BroadcastSubscription(_StreamControllerLifecycle controller, |
| 32 void onData(T data), |
| 33 Function onError, |
| 34 void onDone(), |
| 32 bool cancelOnError) | 35 bool cancelOnError) |
| 33 : super(controller, cancelOnError) { | 36 : super(controller, onData, onError, onDone, cancelOnError) { |
| 34 _next = _previous = this; | 37 _next = _previous = this; |
| 35 } | 38 } |
| 36 | 39 |
| 37 _BroadcastStreamController get _controller => super._controller; | 40 _BroadcastStreamController get _controller => super._controller; |
| 38 | 41 |
| 39 bool _expectsEvent(int eventId) => | 42 bool _expectsEvent(int eventId) => |
| 40 (_eventState & _STATE_EVENT_ID) == eventId; | 43 (_eventState & _STATE_EVENT_ID) == eventId; |
| 41 | 44 |
| 42 void _toggleEventId() { | 45 void _toggleEventId() { |
| 43 _eventState ^= _STATE_EVENT_ID; | 46 _eventState ^= _STATE_EVENT_ID; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 assert(!identical(subscription._next, subscription)); | 174 assert(!identical(subscription._next, subscription)); |
| 172 _BroadcastSubscriptionLink previous = subscription._previous; | 175 _BroadcastSubscriptionLink previous = subscription._previous; |
| 173 _BroadcastSubscriptionLink next = subscription._next; | 176 _BroadcastSubscriptionLink next = subscription._next; |
| 174 previous._next = next; | 177 previous._next = next; |
| 175 next._previous = previous; | 178 next._previous = previous; |
| 176 subscription._next = subscription._previous = subscription; | 179 subscription._next = subscription._previous = subscription; |
| 177 } | 180 } |
| 178 | 181 |
| 179 // _StreamControllerLifecycle interface. | 182 // _StreamControllerLifecycle interface. |
| 180 | 183 |
| 181 StreamSubscription<T> _subscribe(bool cancelOnError) { | 184 StreamSubscription<T> _subscribe( |
| 185 void onData(T data), |
| 186 Function onError, |
| 187 void onDone(), |
| 188 bool cancelOnError) { |
| 182 if (isClosed) { | 189 if (isClosed) { |
| 183 return new _DoneStreamSubscription<T>(_nullDoneHandler); | 190 if (onDone == null) onDone = _nullDoneHandler; |
| 191 return new _DoneStreamSubscription<T>(onDone); |
| 184 } | 192 } |
| 185 StreamSubscription subscription = | 193 StreamSubscription subscription = |
| 186 new _BroadcastSubscription<T>(this, cancelOnError); | 194 new _BroadcastSubscription<T>(this, onData, onError, onDone, |
| 195 cancelOnError); |
| 187 _addListener(subscription); | 196 _addListener(subscription); |
| 188 if (identical(_next, _previous)) { | 197 if (identical(_next, _previous)) { |
| 189 // Only one listener, so it must be the first listener. | 198 // Only one listener, so it must be the first listener. |
| 190 _runGuarded(_onListen); | 199 _runGuarded(_onListen); |
| 191 } | 200 } |
| 192 return subscription; | 201 return subscription; |
| 193 } | 202 } |
| 194 | 203 |
| 195 Future _recordCancel(_BroadcastSubscription<T> subscription) { | 204 Future _recordCancel(_BroadcastSubscription<T> subscription) { |
| 196 // If already removed by the stream, don't remove it again. | 205 // If already removed by the stream, don't remove it again. |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 _pauseCount++; | 497 _pauseCount++; |
| 489 } | 498 } |
| 490 void resume() { _resume(null); } | 499 void resume() { _resume(null); } |
| 491 void _resume(_) { | 500 void _resume(_) { |
| 492 if (_pauseCount > 0) _pauseCount--; | 501 if (_pauseCount > 0) _pauseCount--; |
| 493 } | 502 } |
| 494 Future cancel() { return new _Future.immediate(null); } | 503 Future cancel() { return new _Future.immediate(null); } |
| 495 bool get isPaused => _pauseCount > 0; | 504 bool get isPaused => _pauseCount > 0; |
| 496 Future asFuture([Object value]) => new _Future(); | 505 Future asFuture([Object value]) => new _Future(); |
| 497 } | 506 } |
| OLD | NEW |