| OLD | NEW |
| 1 part of dart.async; | 1 part of dart.async; |
| 2 | 2 abstract class StreamController<T> implements StreamSink<T> {Stream<T> get stre
am; |
| 3 abstract class StreamController<T> implements StreamSink<T> { | 3 factory StreamController({ |
| 4 Stream<T> get stream; | 4 void onListen(), void onPause(), void onResume(), onCancel(), bool sync : fals
e} |
| 5 factory StreamController({void onListen(), void onPause(), void onResume(), | 5 ) { |
| 6 onCancel(), bool sync: false}) { | 6 if (onListen == null && onPause == null && onResume == null && onCancel == nul
l) { |
| 7 if (onListen == null && | 7 return ((__x90) => DDC$RT.cast(__x90, DDC$RT.type((_StreamController<dynamic
> _) { |
| 8 onPause == null && | 8 } |
| 9 onResume == null && | 9 ), DDC$RT.type((StreamController<T> _) { |
| 10 onCancel == null) { | 10 } |
| 11 return ((__x90) => DDC$RT.cast(__x90, | 11 ), "CastDynamic", """line 83, column 14 of dart:async/stream_controller.dart
: """, __x90 is StreamController<T>, false))(sync ? new _NoCallbackSyncStreamCon
troller() : new _NoCallbackAsyncStreamController()); |
| 12 DDC$RT.type((_StreamController<dynamic> _) {}), | |
| 13 DDC$RT.type((StreamController<T> _) {}), "CastDynamic", | |
| 14 """line 83, column 14 of dart:async/stream_controller.dart: """, | |
| 15 __x90 is StreamController<T>, false))(sync | |
| 16 ? new _NoCallbackSyncStreamController() | |
| 17 : new _NoCallbackAsyncStreamController()); | |
| 18 } | 12 } |
| 19 return sync | 13 return sync ? new _SyncStreamController<T>(onListen, onPause, onResume, onCan
cel) : new _AsyncStreamController<T>(onListen, onPause, onResume, onCancel); |
| 20 ? new _SyncStreamController<T>(onListen, onPause, onResume, onCancel) | 14 } |
| 21 : new _AsyncStreamController<T>(onListen, onPause, onResume, onCancel); | 15 factory StreamController.broadcast({ |
| 22 } | 16 void onListen(), void onCancel(), bool sync : false} |
| 23 factory StreamController.broadcast( | 17 ) { |
| 24 {void onListen(), void onCancel(), bool sync: false}) { | 18 return sync ? new _SyncBroadcastStreamController<T>(onListen, onCancel) : new
_AsyncBroadcastStreamController<T>(onListen, onCancel); |
| 25 return sync | 19 } |
| 26 ? new _SyncBroadcastStreamController<T>(onListen, onCancel) | 20 StreamSink<T> get sink; |
| 27 : new _AsyncBroadcastStreamController<T>(onListen, onCancel); | 21 bool get isClosed; |
| 28 } | 22 bool get isPaused; |
| 29 StreamSink<T> get sink; | 23 bool get hasListener; |
| 30 bool get isClosed; | 24 void addError(Object error, [StackTrace stackTrace]); |
| 31 bool get isPaused; | 25 Future addStream(Stream<T> source, { |
| 32 bool get hasListener; | 26 bool cancelOnError : true} |
| 33 void addError(Object error, [StackTrace stackTrace]); | 27 ); |
| 34 Future addStream(Stream<T> source, {bool cancelOnError: true}); | 28 } |
| 35 } | 29 abstract class _StreamControllerLifecycle<T> {StreamSubscription<T> _subscribe(
void onData(T data), Function onError, void onDone(), bool cancelOnError); |
| 36 abstract class _StreamControllerLifecycle<T> { | 30 void _recordPause(StreamSubscription<T> subscription) { |
| 37 StreamSubscription<T> _subscribe( | 31 } |
| 38 void onData(T data), Function onError, void onDone(), bool cancelOnError); | 32 void _recordResume(StreamSubscription<T> subscription) { |
| 39 void _recordPause(StreamSubscription<T> subscription) {} | 33 } |
| 40 void _recordResume(StreamSubscription<T> subscription) {} | 34 Future _recordCancel(StreamSubscription<T> subscription) => null; |
| 41 Future _recordCancel(StreamSubscription<T> subscription) => null; | 35 } |
| 42 } | 36 abstract class _StreamController<T> implements StreamController<T>, _StreamCont
rollerLifecycle<T>, _EventSink<T>, _EventDispatch<T> {static const int _STATE_IN
ITIAL = 0; |
| 43 abstract class _StreamController<T> | 37 static const int _STATE_SUBSCRIBED = 1; |
| 44 implements StreamController<T>, _StreamControllerLifecycle<T>, _EventSink<T>
, _EventDispatch<T> { | 38 static const int _STATE_CANCELED = 2; |
| 45 static const int _STATE_INITIAL = 0; | 39 static const int _STATE_SUBSCRIPTION_MASK = 3; |
| 46 static const int _STATE_SUBSCRIBED = 1; | 40 static const int _STATE_CLOSED = 4; |
| 47 static const int _STATE_CANCELED = 2; | 41 static const int _STATE_ADDSTREAM = 8; |
| 48 static const int _STATE_SUBSCRIPTION_MASK = 3; | 42 var _varData; |
| 49 static const int _STATE_CLOSED = 4; | 43 int _state = _STATE_INITIAL; |
| 50 static const int _STATE_ADDSTREAM = 8; | 44 _Future _doneFuture; |
| 51 var _varData; | 45 _StreamController(); |
| 52 int _state = _STATE_INITIAL; | 46 _NotificationHandler get _onListen; |
| 53 _Future _doneFuture; | 47 _NotificationHandler get _onPause; |
| 54 _StreamController(); | 48 _NotificationHandler get _onResume; |
| 55 _NotificationHandler get _onListen; | 49 _NotificationHandler get _onCancel; |
| 56 _NotificationHandler get _onPause; | 50 Stream<T> get stream => ((__x91) => DDC$RT.cast(__x91, DDC$RT.type((_Controller
Stream<dynamic> _) { |
| 57 _NotificationHandler get _onResume; | 51 } |
| 58 _NotificationHandler get _onCancel; | 52 ), DDC$RT.type((Stream<T> _) { |
| 59 Stream<T> get stream => ((__x91) => DDC$RT.cast(__x91, | 53 } |
| 60 DDC$RT.type((_ControllerStream<dynamic> _) {}), | 54 ), "CastExact", """line 293, column 27 of dart:async/stream_controller.dart: """
, __x91 is Stream<T>, false))(new _ControllerStream(this)); |
| 61 DDC$RT.type((Stream<T> _) {}), "CastExact", | 55 StreamSink<T> get sink => new _StreamSinkWrapper<T>(this); |
| 62 """line 293, column 27 of dart:async/stream_controller.dart: """, | 56 bool get _isCanceled => (_state & _STATE_CANCELED) != 0; |
| 63 __x91 is Stream<T>, false))(new _ControllerStream(this)); | 57 bool get hasListener => (_state & _STATE_SUBSCRIBED) != 0; |
| 64 StreamSink<T> get sink => new _StreamSinkWrapper<T>(this); | 58 bool get _isInitialState => (_state & _STATE_SUBSCRIPTION_MASK) == _STATE_INITI
AL; |
| 65 bool get _isCanceled => (_state & _STATE_CANCELED) != 0; | 59 bool get isClosed => (_state & _STATE_CLOSED) != 0; |
| 66 bool get hasListener => (_state & _STATE_SUBSCRIBED) != 0; | 60 bool get isPaused => hasListener ? _subscription._isInputPaused : !_isCanceled; |
| 67 bool get _isInitialState => | 61 bool get _isAddingStream => (_state & _STATE_ADDSTREAM) != 0; |
| 68 (_state & _STATE_SUBSCRIPTION_MASK) == _STATE_INITIAL; | 62 bool get _mayAddEvent => (_state < _STATE_CLOSED); |
| 69 bool get isClosed => (_state & _STATE_CLOSED) != 0; | 63 _PendingEvents get _pendingEvents { |
| 70 bool get isPaused => | 64 assert (_isInitialState); if (!_isAddingStream) { |
| 71 hasListener ? _subscription._isInputPaused : !_isCanceled; | 65 return DDC$RT.cast(_varData, dynamic, _PendingEvents, "CastGeneral", """line 334
, column 14 of dart:async/stream_controller.dart: """, _varData is _PendingEvent
s, true); |
| 72 bool get _isAddingStream => (_state & _STATE_ADDSTREAM) != 0; | 66 } |
| 73 bool get _mayAddEvent => (_state < _STATE_CLOSED); | 67 _StreamControllerAddStreamState state = DDC$RT.cast(_varData, dynamic, DDC$RT.t
ype((_StreamControllerAddStreamState<dynamic> _) { |
| 74 _PendingEvents get _pendingEvents { | 68 } |
| 75 assert(_isInitialState); | 69 ), "CastGeneral", """line 336, column 45 of dart:async/stream_controller.dart: "
"", _varData is _StreamControllerAddStreamState<dynamic>, true); |
| 76 if (!_isAddingStream) { | 70 return DDC$RT.cast(state.varData, dynamic, _PendingEvents, "CastGeneral", """li
ne 337, column 12 of dart:async/stream_controller.dart: """, state.varData is _P
endingEvents, true); |
| 77 return DDC$RT.cast(_varData, dynamic, _PendingEvents, "CastGeneral", | 71 } |
| 78 """line 334, column 14 of dart:async/stream_controller.dart: """, | 72 _StreamImplEvents _ensurePendingEvents() { |
| 79 _varData is _PendingEvents, true); | 73 assert (_isInitialState); if (!_isAddingStream) { |
| 74 if (_varData == null) _varData = new _StreamImplEvents(); |
| 75 return DDC$RT.cast(_varData, dynamic, _StreamImplEvents, "CastGeneral", """line
345, column 14 of dart:async/stream_controller.dart: """, _varData is _StreamIm
plEvents, true); |
| 76 } |
| 77 _StreamControllerAddStreamState state = DDC$RT.cast(_varData, dynamic, DDC$RT.t
ype((_StreamControllerAddStreamState<dynamic> _) { |
| 78 } |
| 79 ), "CastGeneral", """line 347, column 45 of dart:async/stream_controller.dart: "
"", _varData is _StreamControllerAddStreamState<dynamic>, true); |
| 80 if (state.varData == null) state.varData = new _StreamImplEvents(); |
| 81 return DDC$RT.cast(state.varData, dynamic, _StreamImplEvents, "CastGeneral", ""
"line 349, column 12 of dart:async/stream_controller.dart: """, state.varData is
_StreamImplEvents, true); |
| 82 } |
| 83 _ControllerSubscription get _subscription { |
| 84 assert (hasListener); if (_isAddingStream) { |
| 85 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, DDC$RT
.type((_StreamControllerAddStreamState<dynamic> _) { |
| 86 } |
| 87 ), "CastGeneral", """line 358, column 50 of dart:async/stream_controller.dart: "
"", _varData is _StreamControllerAddStreamState<dynamic>, true); |
| 88 return DDC$RT.cast(addState.varData, dynamic, DDC$RT.type((_ControllerSubscript
ion<dynamic> _) { |
| 89 } |
| 90 ), "CastGeneral", """line 359, column 14 of dart:async/stream_controller.dart: "
"", addState.varData is _ControllerSubscription<dynamic>, true); |
| 91 } |
| 92 return DDC$RT.cast(_varData, dynamic, DDC$RT.type((_ControllerSubscription<dyna
mic> _) { |
| 93 } |
| 94 ), "CastGeneral", """line 361, column 12 of dart:async/stream_controller.dart: "
"", _varData is _ControllerSubscription<dynamic>, true); |
| 95 } |
| 96 Error _badEventState() { |
| 97 if (isClosed) { |
| 98 return new StateError("Cannot add event after closing"); |
| 99 } |
| 100 assert (_isAddingStream); return new StateError("Cannot add event while adding
a stream"); |
| 101 } |
| 102 Future addStream(Stream<T> source, { |
| 103 bool cancelOnError : true} |
| 104 ) { |
| 105 if (!_mayAddEvent) throw _badEventState(); |
| 106 if (_isCanceled) return new _Future.immediate(null); |
| 107 _StreamControllerAddStreamState addState = new _StreamControllerAddStreamState(
this, _varData, source, cancelOnError); |
| 108 _varData = addState; |
| 109 _state |= _STATE_ADDSTREAM; |
| 110 return addState.addStreamFuture; |
| 111 } |
| 112 Future get done => _ensureDoneFuture(); |
| 113 Future _ensureDoneFuture() { |
| 114 if (_doneFuture == null) { |
| 115 _doneFuture = _isCanceled ? Future._nullFuture : new _Future(); |
| 116 } |
| 117 return _doneFuture; |
| 118 } |
| 119 void add(T value) { |
| 120 if (!_mayAddEvent) throw _badEventState(); |
| 121 _add(value); |
| 122 } |
| 123 void addError(Object error, [StackTrace stackTrace]) { |
| 124 error = _nonNullError(error); |
| 125 if (!_mayAddEvent) throw _badEventState(); |
| 126 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); |
| 127 if (replacement != null) { |
| 128 error = _nonNullError(replacement.error); |
| 129 stackTrace = replacement.stackTrace; |
| 130 } |
| 131 _addError(error, stackTrace); |
| 132 } |
| 133 Future close() { |
| 134 if (isClosed) { |
| 135 return _ensureDoneFuture(); |
| 136 } |
| 137 if (!_mayAddEvent) throw _badEventState(); |
| 138 _closeUnchecked(); |
| 139 return _ensureDoneFuture(); |
| 140 } |
| 141 void _closeUnchecked() { |
| 142 _state |= _STATE_CLOSED; |
| 143 if (hasListener) { |
| 144 _sendDone(); |
| 145 } |
| 146 else if (_isInitialState) { |
| 147 _ensurePendingEvents().add(const _DelayedDone()); |
| 148 } |
| 149 } |
| 150 void _add(T value) { |
| 151 if (hasListener) { |
| 152 _sendData(value); |
| 153 } |
| 154 else if (_isInitialState) { |
| 155 _ensurePendingEvents().add(new _DelayedData<T>(value)); |
| 156 } |
| 157 } |
| 158 void _addError(Object error, StackTrace stackTrace) { |
| 159 if (hasListener) { |
| 160 _sendError(error, stackTrace); |
| 161 } |
| 162 else if (_isInitialState) { |
| 163 _ensurePendingEvents().add(new _DelayedError(error, stackTrace)); |
| 164 } |
| 165 } |
| 166 void _close() { |
| 167 assert (_isAddingStream); _StreamControllerAddStreamState addState = DDC$RT.cast
(_varData, dynamic, DDC$RT.type((_StreamControllerAddStreamState<dynamic> _) { |
| 168 } |
| 169 ), "CastGeneral", """line 482, column 48 of dart:async/stream_controller.dart: "
"", _varData is _StreamControllerAddStreamState<dynamic>, true); |
| 170 _varData = addState.varData; |
| 171 _state &= ~_STATE_ADDSTREAM; |
| 172 addState.complete(); |
| 173 } |
| 174 StreamSubscription<T> _subscribe(void onData(T data), Function onError, void on
Done(), bool cancelOnError) { |
| 175 if (!_isInitialState) { |
| 176 throw new StateError("Stream has already been listened to."); |
| 177 } |
| 178 _ControllerSubscription subscription = new _ControllerSubscription(this, onData
, onError, onDone, cancelOnError); |
| 179 _PendingEvents pendingEvents = _pendingEvents; |
| 180 _state |= _STATE_SUBSCRIBED; |
| 181 if (_isAddingStream) { |
| 182 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, DDC$RT
.type((_StreamControllerAddStreamState<dynamic> _) { |
| 183 } |
| 184 ), "CastGeneral", """line 505, column 50 of dart:async/stream_controller.dart: "
"", _varData is _StreamControllerAddStreamState<dynamic>, true); |
| 185 addState.varData = subscription; |
| 186 addState.resume(); |
| 187 } |
| 188 else { |
| 189 _varData = subscription; |
| 190 } |
| 191 subscription._setPendingEvents(pendingEvents); |
| 192 subscription._guardCallback(() { |
| 193 _runGuarded(_onListen); |
| 194 } |
| 195 ); |
| 196 return DDC$RT.cast(subscription, DDC$RT.type((_ControllerSubscription<dynamic>
_) { |
| 197 } |
| 198 ), DDC$RT.type((StreamSubscription<T> _) { |
| 199 } |
| 200 ), "CastDynamic", """line 516, column 12 of dart:async/stream_controller.dart: "
"", subscription is StreamSubscription<T>, false); |
| 201 } |
| 202 Future _recordCancel(StreamSubscription<T> subscription) { |
| 203 Future result; |
| 204 if (_isAddingStream) { |
| 205 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, DDC$RT
.type((_StreamControllerAddStreamState<dynamic> _) { |
| 206 } |
| 207 ), "CastGeneral", """line 530, column 50 of dart:async/stream_controller.dart: "
"", _varData is _StreamControllerAddStreamState<dynamic>, true); |
| 208 result = addState.cancel(); |
| 209 } |
| 210 _varData = null; |
| 211 _state = (_state & ~(_STATE_SUBSCRIBED | _STATE_ADDSTREAM)) | _STATE_CANCELED; |
| 212 if (_onCancel != null) { |
| 213 if (result == null) { |
| 214 try { |
| 215 result = ((__x92) => DDC$RT.cast(__x92, dynamic, DDC$RT.type((Future<dynamic
> _) { |
| 216 } |
| 217 ), "CastGeneral", """line 542, column 20 of dart:async/stream_controller.dar
t: """, __x92 is Future<dynamic>, true))(_onCancel()); |
| 80 } | 218 } |
| 81 _StreamControllerAddStreamState state = DDC$RT.cast(_varData, dynamic, | 219 catch (e, s) { |
| 82 DDC$RT.type((_StreamControllerAddStreamState<dynamic> _) {}), | 220 result = new _Future().._asyncCompleteError(e, s); |
| 83 "CastGeneral", | |
| 84 """line 336, column 45 of dart:async/stream_controller.dart: """, | |
| 85 _varData is _StreamControllerAddStreamState<dynamic>, true); | |
| 86 return DDC$RT.cast(state.varData, dynamic, _PendingEvents, "CastGeneral", | |
| 87 """line 337, column 12 of dart:async/stream_controller.dart: """, | |
| 88 state.varData is _PendingEvents, true); | |
| 89 } | |
| 90 _StreamImplEvents _ensurePendingEvents() { | |
| 91 assert(_isInitialState); | |
| 92 if (!_isAddingStream) { | |
| 93 if (_varData == null) _varData = new _StreamImplEvents(); | |
| 94 return DDC$RT.cast(_varData, dynamic, _StreamImplEvents, "CastGeneral", | |
| 95 """line 345, column 14 of dart:async/stream_controller.dart: """, | |
| 96 _varData is _StreamImplEvents, true); | |
| 97 } | 221 } |
| 98 _StreamControllerAddStreamState state = DDC$RT.cast(_varData, dynamic, | 222 } |
| 99 DDC$RT.type((_StreamControllerAddStreamState<dynamic> _) {}), | 223 else { |
| 100 "CastGeneral", | 224 result = result.whenComplete(_onCancel); |
| 101 """line 347, column 45 of dart:async/stream_controller.dart: """, | 225 } |
| 102 _varData is _StreamControllerAddStreamState<dynamic>, true); | 226 } |
| 103 if (state.varData == null) state.varData = new _StreamImplEvents(); | 227 void complete() { |
| 104 return DDC$RT.cast(state.varData, dynamic, _StreamImplEvents, "CastGeneral", | 228 if (_doneFuture != null && _doneFuture._mayComplete) { |
| 105 """line 349, column 12 of dart:async/stream_controller.dart: """, | 229 _doneFuture._asyncComplete(null); |
| 106 state.varData is _StreamImplEvents, true); | 230 } |
| 107 } | 231 } |
| 108 _ControllerSubscription get _subscription { | 232 if (result != null) { |
| 109 assert(hasListener); | 233 result = result.whenComplete(complete); |
| 110 if (_isAddingStream) { | 234 } |
| 111 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, | 235 else { |
| 112 DDC$RT.type((_StreamControllerAddStreamState<dynamic> _) {}), | 236 complete(); |
| 113 "CastGeneral", | 237 } |
| 114 """line 358, column 50 of dart:async/stream_controller.dart: """, | 238 return result; |
| 115 _varData is _StreamControllerAddStreamState<dynamic>, true); | 239 } |
| 116 return DDC$RT.cast(addState.varData, dynamic, | 240 void _recordPause(StreamSubscription<T> subscription) { |
| 117 DDC$RT.type((_ControllerSubscription<dynamic> _) {}), "CastGeneral", | 241 if (_isAddingStream) { |
| 118 """line 359, column 14 of dart:async/stream_controller.dart: """, | 242 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, DDC$RT
.type((_StreamControllerAddStreamState<dynamic> _) { |
| 119 addState.varData is _ControllerSubscription<dynamic>, true); | 243 } |
| 120 } | 244 ), "CastGeneral", """line 572, column 50 of dart:async/stream_controller.dart: "
"", _varData is _StreamControllerAddStreamState<dynamic>, true); |
| 121 return DDC$RT.cast(_varData, dynamic, | 245 addState.pause(); |
| 122 DDC$RT.type((_ControllerSubscription<dynamic> _) {}), "CastGeneral", | 246 } |
| 123 """line 361, column 12 of dart:async/stream_controller.dart: """, | 247 _runGuarded(_onPause); |
| 124 _varData is _ControllerSubscription<dynamic>, true); | 248 } |
| 125 } | 249 void _recordResume(StreamSubscription<T> subscription) { |
| 126 Error _badEventState() { | 250 if (_isAddingStream) { |
| 127 if (isClosed) { | 251 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, DDC$RT
.type((_StreamControllerAddStreamState<dynamic> _) { |
| 128 return new StateError("Cannot add event after closing"); | 252 } |
| 129 } | 253 ), "CastGeneral", """line 580, column 50 of dart:async/stream_controller.dart: "
"", _varData is _StreamControllerAddStreamState<dynamic>, true); |
| 130 assert(_isAddingStream); | 254 addState.resume(); |
| 131 return new StateError("Cannot add event while adding a stream"); | 255 } |
| 132 } | 256 _runGuarded(_onResume); |
| 133 Future addStream(Stream<T> source, {bool cancelOnError: true}) { | 257 } |
| 134 if (!_mayAddEvent) throw _badEventState(); | 258 } |
| 135 if (_isCanceled) return new _Future.immediate(null); | 259 abstract class _SyncStreamControllerDispatch<T> implements _StreamController<T>
{void _sendData(T data) { |
| 136 _StreamControllerAddStreamState addState = | 260 _subscription._add(data); |
| 137 new _StreamControllerAddStreamState( | 261 } |
| 138 this, _varData, source, cancelOnError); | 262 void _sendError(Object error, StackTrace stackTrace) { |
| 139 _varData = addState; | 263 _subscription._addError(error, stackTrace); |
| 140 _state |= _STATE_ADDSTREAM; | 264 } |
| 141 return addState.addStreamFuture; | 265 void _sendDone() { |
| 142 } | 266 _subscription._close(); |
| 143 Future get done => _ensureDoneFuture(); | 267 } |
| 144 Future _ensureDoneFuture() { | 268 } |
| 145 if (_doneFuture == null) { | 269 abstract class _AsyncStreamControllerDispatch<T> implements _StreamController<T
> {void _sendData(T data) { |
| 146 _doneFuture = _isCanceled ? Future._nullFuture : new _Future(); | 270 _subscription._addPending(new _DelayedData(data)); |
| 147 } | 271 } |
| 148 return _doneFuture; | 272 void _sendError(Object error, StackTrace stackTrace) { |
| 149 } | 273 _subscription._addPending(new _DelayedError(error, stackTrace)); |
| 150 void add(T value) { | 274 } |
| 151 if (!_mayAddEvent) throw _badEventState(); | 275 void _sendDone() { |
| 152 _add(value); | 276 _subscription._addPending(const _DelayedDone()); |
| 153 } | 277 } |
| 154 void addError(Object error, [StackTrace stackTrace]) { | 278 } |
| 155 error = _nonNullError(error); | 279 class _AsyncStreamController<T> extends _StreamController<T> with _AsyncStreamC
ontrollerDispatch<T> {final _NotificationHandler _onListen; |
| 156 if (!_mayAddEvent) throw _badEventState(); | 280 final _NotificationHandler _onPause; |
| 157 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); | 281 final _NotificationHandler _onResume; |
| 158 if (replacement != null) { | 282 final _NotificationHandler _onCancel; |
| 159 error = _nonNullError(replacement.error); | 283 _AsyncStreamController(void this._onListen(), void this._onPause(), void this._
onResume(), this._onCancel()); |
| 160 stackTrace = replacement.stackTrace; | 284 } |
| 161 } | 285 class _SyncStreamController<T> extends _StreamController<T> with _SyncStreamCon
trollerDispatch<T> {final _NotificationHandler _onListen; |
| 162 _addError(error, stackTrace); | 286 final _NotificationHandler _onPause; |
| 163 } | 287 final _NotificationHandler _onResume; |
| 164 Future close() { | 288 final _NotificationHandler _onCancel; |
| 165 if (isClosed) { | 289 _SyncStreamController(void this._onListen(), void this._onPause(), void this._o
nResume(), this._onCancel()); |
| 166 return _ensureDoneFuture(); | 290 } |
| 167 } | 291 abstract class _NoCallbacks {_NotificationHandler get _onListen => null; |
| 168 if (!_mayAddEvent) throw _badEventState(); | 292 _NotificationHandler get _onPause => null; |
| 169 _closeUnchecked(); | 293 _NotificationHandler get _onResume => null; |
| 170 return _ensureDoneFuture(); | 294 _NotificationHandler get _onCancel => null; |
| 171 } | 295 } |
| 172 void _closeUnchecked() { | 296 class _NoCallbackAsyncStreamController = _StreamController with _AsyncStreamCon
trollerDispatch, _NoCallbacks; |
| 173 _state |= _STATE_CLOSED; | 297 class _NoCallbackSyncStreamController = _StreamController with _SyncStreamContr
ollerDispatch, _NoCallbacks; |
| 174 if (hasListener) { | 298 typedef _NotificationHandler(); |
| 175 _sendDone(); | 299 Future _runGuarded(_NotificationHandler notificationHandler) { |
| 176 } else if (_isInitialState) { | 300 if (notificationHandler == null) return null; |
| 177 _ensurePendingEvents().add(const _DelayedDone()); | 301 try { |
| 178 } | 302 var result = notificationHandler(); |
| 179 } | 303 if (result is Future) return DDC$RT.cast(result, dynamic, DDC$RT.type((Future<d
ynamic> _) { |
| 180 void _add(T value) { | 304 } |
| 181 if (hasListener) { | 305 ), "CastGeneral", """line 665, column 34 of dart:async/stream_controller.dart: "
"", result is Future<dynamic>, true); |
| 182 _sendData(value); | 306 return null; |
| 183 } else if (_isInitialState) { | 307 } |
| 184 _ensurePendingEvents().add(new _DelayedData<T>(value)); | 308 catch (e, s) { |
| 185 } | 309 Zone.current.handleUncaughtError(e, s); |
| 186 } | 310 } |
| 187 void _addError(Object error, StackTrace stackTrace) { | 311 } |
| 188 if (hasListener) { | 312 class _ControllerStream<T> extends _StreamImpl<T> {_StreamControllerLifecycle<T
> _controller; |
| 189 _sendError(error, stackTrace); | 313 _ControllerStream(this._controller); |
| 190 } else if (_isInitialState) { | 314 StreamSubscription<T> _createSubscription(void onData(T data), Function onError
, void onDone(), bool cancelOnError) => _controller._subscribe(onData, onError,
onDone, cancelOnError); |
| 191 _ensurePendingEvents().add(new _DelayedError(error, stackTrace)); | 315 int get hashCode => _controller.hashCode ^ 0x35323532; |
| 192 } | 316 bool operator ==(Object other) { |
| 193 } | 317 if (identical(this, other)) return true; |
| 194 void _close() { | 318 if (other is! _ControllerStream) return false; |
| 195 assert(_isAddingStream); | 319 _ControllerStream otherStream = DDC$RT.cast(other, Object, DDC$RT.type((_Contro
llerStream<dynamic> _) { |
| 196 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, | 320 } |
| 197 DDC$RT.type((_StreamControllerAddStreamState<dynamic> _) {}), | 321 ), "CastGeneral", """line 693, column 37 of dart:async/stream_controller.dart: "
"", other is _ControllerStream<dynamic>, true); |
| 198 "CastGeneral", | 322 return identical(otherStream._controller, this._controller); |
| 199 """line 482, column 48 of dart:async/stream_controller.dart: """, | 323 } |
| 200 _varData is _StreamControllerAddStreamState<dynamic>, true); | 324 } |
| 201 _varData = addState.varData; | 325 class _ControllerSubscription<T> extends _BufferingStreamSubscription<T> {final
_StreamControllerLifecycle<T> _controller; |
| 202 _state &= ~_STATE_ADDSTREAM; | 326 _ControllerSubscription(this._controller, void onData(T data), Function onError
, void onDone(), bool cancelOnError) : super(onData, onError, onDone, cancelOnEr
ror); |
| 203 addState.complete(); | 327 Future _onCancel() { |
| 204 } | 328 return _controller._recordCancel(this); |
| 205 StreamSubscription<T> _subscribe(void onData(T data), Function onError, | 329 } |
| 206 void onDone(), bool cancelOnError) { | 330 void _onPause() { |
| 207 if (!_isInitialState) { | 331 _controller._recordPause(this); |
| 208 throw new StateError("Stream has already been listened to."); | 332 } |
| 209 } | 333 void _onResume() { |
| 210 _ControllerSubscription subscription = new _ControllerSubscription( | 334 _controller._recordResume(this); |
| 211 this, onData, onError, onDone, cancelOnError); | 335 } |
| 212 _PendingEvents pendingEvents = _pendingEvents; | 336 } |
| 213 _state |= _STATE_SUBSCRIBED; | 337 class _StreamSinkWrapper<T> implements StreamSink<T> {final StreamController _t
arget; |
| 214 if (_isAddingStream) { | 338 _StreamSinkWrapper(this._target); |
| 215 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, | 339 void add(T data) { |
| 216 DDC$RT.type((_StreamControllerAddStreamState<dynamic> _) {}), | 340 _target.add(data); |
| 217 "CastGeneral", | 341 } |
| 218 """line 505, column 50 of dart:async/stream_controller.dart: """, | 342 void addError(Object error, [StackTrace stackTrace]) { |
| 219 _varData is _StreamControllerAddStreamState<dynamic>, true); | 343 _target.addError(error, stackTrace); |
| 220 addState.varData = subscription; | 344 } |
| 221 addState.resume(); | 345 Future close() => _target.close(); |
| 222 } else { | 346 Future addStream(Stream<T> source, { |
| 223 _varData = subscription; | 347 bool cancelOnError : true} |
| 224 } | 348 ) => _target.addStream(source, cancelOnError: cancelOnError); |
| 225 subscription._setPendingEvents(pendingEvents); | 349 Future get done => _target.done; |
| 226 subscription._guardCallback(() { | 350 } |
| 227 _runGuarded(_onListen); | 351 class _AddStreamState<T> {final _Future addStreamFuture; |
| 228 }); | 352 final StreamSubscription addSubscription; |
| 229 return DDC$RT.cast(subscription, | 353 _AddStreamState(_EventSink<T> controller, Stream source, bool cancelOnError) :
addStreamFuture = new _Future(), addSubscription = source.listen(DDC$RT.wrap((vo
id f(T __u93)) { |
| 230 DDC$RT.type((_ControllerSubscription<dynamic> _) {}), | 354 void c(T x0) => f(DDC$RT.cast(x0, dynamic, T, "CastParam", """line 745, column 4
1 of dart:async/stream_controller.dart: """, x0 is T, false)); |
| 231 DDC$RT.type((StreamSubscription<T> _) {}), "CastDynamic", | 355 return f == null ? null : c; |
| 232 """line 516, column 12 of dart:async/stream_controller.dart: """, | 356 } |
| 233 subscription is StreamSubscription<T>, false); | 357 , controller._add, DDC$RT.type((__t96<T> _) { |
| 234 } | 358 } |
| 235 Future _recordCancel(StreamSubscription<T> subscription) { | 359 ), __t94, "Wrap", """line 745, column 41 of dart:async/stream_controller.dart: "
"", controller._add is __t94), onError: ((__x98) => DDC$RT.cast(__x98, dynamic,
Function, "CastGeneral", """line 746, column 50 of dart:async/stream_controller.
dart: """, __x98 is Function, true))(cancelOnError ? makeErrorHandler(controller
) : controller._addError), onDone: controller._close, cancelOnError: cancelOnErr
or); |
| 236 Future result; | 360 static makeErrorHandler(_EventSink controller) => (e, StackTrace s) { |
| 237 if (_isAddingStream) { | 361 controller._addError(e, s); |
| 238 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, | 362 controller._close(); |
| 239 DDC$RT.type((_StreamControllerAddStreamState<dynamic> _) {}), | 363 } |
| 240 "CastGeneral", | 364 ; |
| 241 """line 530, column 50 of dart:async/stream_controller.dart: """, | 365 void pause() { |
| 242 _varData is _StreamControllerAddStreamState<dynamic>, true); | 366 addSubscription.pause(); |
| 243 result = addState.cancel(); | 367 } |
| 244 } | 368 void resume() { |
| 245 _varData = null; | 369 addSubscription.resume(); |
| 246 _state = | 370 } |
| 247 (_state & ~(_STATE_SUBSCRIBED | _STATE_ADDSTREAM)) | _STATE_CANCELED; | 371 Future cancel() { |
| 248 if (_onCancel != null) { | 372 var cancel = addSubscription.cancel(); |
| 249 if (result == null) { | 373 if (cancel == null) { |
| 250 try { | 374 addStreamFuture._asyncComplete(null); |
| 251 result = ((__x92) => DDC$RT.cast(__x92, dynamic, | 375 return null; |
| 252 DDC$RT.type((Future<dynamic> _) {}), "CastGeneral", | 376 } |
| 253 """line 542, column 20 of dart:async/stream_controller.dart: """, | 377 return cancel.whenComplete(() { |
| 254 __x92 is Future<dynamic>, true))(_onCancel()); | 378 addStreamFuture._asyncComplete(null); |
| 255 } catch (e, s) { | 379 } |
| 256 result = new _Future().._asyncCompleteError(e, s); | 380 ); |
| 257 } | 381 } |
| 258 } else { | 382 void complete() { |
| 259 result = result.whenComplete(_onCancel); | 383 addStreamFuture._asyncComplete(null); |
| 260 } | 384 } |
| 261 } | 385 } |
| 262 void complete() { | 386 class _StreamControllerAddStreamState<T> extends _AddStreamState<T> {var varDat
a; |
| 263 if (_doneFuture != null && _doneFuture._mayComplete) { | 387 _StreamControllerAddStreamState(_StreamController controller, this.varData, Str
eam source, bool cancelOnError) : super(DDC$RT.cast(controller, DDC$RT.type((_St
reamController<dynamic> _) { |
| 264 _doneFuture._asyncComplete(null); | 388 } |
| 265 } | 389 ), DDC$RT.type((_EventSink<T> _) { |
| 266 } | 390 } |
| 267 if (result != null) { | 391 ), "CastDynamic", """line 798, column 15 of dart:async/stream_controller.dart: "
"", controller is _EventSink<T>, false), source, cancelOnError) { |
| 268 result = result.whenComplete(complete); | 392 if (controller.isPaused) { |
| 269 } else { | 393 addSubscription.pause(); |
| 270 complete(); | 394 } |
| 271 } | 395 } |
| 272 return result; | 396 } |
| 273 } | 397 typedef void __t94(dynamic __u95); |
| 274 void _recordPause(StreamSubscription<T> subscription) { | 398 typedef void __t96<T>(T __u97); |
| 275 if (_isAddingStream) { | |
| 276 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, | |
| 277 DDC$RT.type((_StreamControllerAddStreamState<dynamic> _) {}), | |
| 278 "CastGeneral", | |
| 279 """line 572, column 50 of dart:async/stream_controller.dart: """, | |
| 280 _varData is _StreamControllerAddStreamState<dynamic>, true); | |
| 281 addState.pause(); | |
| 282 } | |
| 283 _runGuarded(_onPause); | |
| 284 } | |
| 285 void _recordResume(StreamSubscription<T> subscription) { | |
| 286 if (_isAddingStream) { | |
| 287 _StreamControllerAddStreamState addState = DDC$RT.cast(_varData, dynamic, | |
| 288 DDC$RT.type((_StreamControllerAddStreamState<dynamic> _) {}), | |
| 289 "CastGeneral", | |
| 290 """line 580, column 50 of dart:async/stream_controller.dart: """, | |
| 291 _varData is _StreamControllerAddStreamState<dynamic>, true); | |
| 292 addState.resume(); | |
| 293 } | |
| 294 _runGuarded(_onResume); | |
| 295 } | |
| 296 } | |
| 297 abstract class _SyncStreamControllerDispatch<T> | |
| 298 implements _StreamController<T> { | |
| 299 void _sendData(T data) { | |
| 300 _subscription._add(data); | |
| 301 } | |
| 302 void _sendError(Object error, StackTrace stackTrace) { | |
| 303 _subscription._addError(error, stackTrace); | |
| 304 } | |
| 305 void _sendDone() { | |
| 306 _subscription._close(); | |
| 307 } | |
| 308 } | |
| 309 abstract class _AsyncStreamControllerDispatch<T> | |
| 310 implements _StreamController<T> { | |
| 311 void _sendData(T data) { | |
| 312 _subscription._addPending(new _DelayedData(data)); | |
| 313 } | |
| 314 void _sendError(Object error, StackTrace stackTrace) { | |
| 315 _subscription._addPending(new _DelayedError(error, stackTrace)); | |
| 316 } | |
| 317 void _sendDone() { | |
| 318 _subscription._addPending(const _DelayedDone()); | |
| 319 } | |
| 320 } | |
| 321 class _AsyncStreamController<T> extends _StreamController<T> | |
| 322 with _AsyncStreamControllerDispatch<T> { | |
| 323 final _NotificationHandler _onListen; | |
| 324 final _NotificationHandler _onPause; | |
| 325 final _NotificationHandler _onResume; | |
| 326 final _NotificationHandler _onCancel; | |
| 327 _AsyncStreamController(void this._onListen(), void this._onPause(), | |
| 328 void this._onResume(), this._onCancel()); | |
| 329 } | |
| 330 class _SyncStreamController<T> extends _StreamController<T> | |
| 331 with _SyncStreamControllerDispatch<T> { | |
| 332 final _NotificationHandler _onListen; | |
| 333 final _NotificationHandler _onPause; | |
| 334 final _NotificationHandler _onResume; | |
| 335 final _NotificationHandler _onCancel; | |
| 336 _SyncStreamController(void this._onListen(), void this._onPause(), | |
| 337 void this._onResume(), this._onCancel()); | |
| 338 } | |
| 339 abstract class _NoCallbacks { | |
| 340 _NotificationHandler get _onListen => null; | |
| 341 _NotificationHandler get _onPause => null; | |
| 342 _NotificationHandler get _onResume => null; | |
| 343 _NotificationHandler get _onCancel => null; | |
| 344 } | |
| 345 class _NoCallbackAsyncStreamController = _StreamController | |
| 346 with _AsyncStreamControllerDispatch, _NoCallbacks; | |
| 347 class _NoCallbackSyncStreamController = _StreamController | |
| 348 with _SyncStreamControllerDispatch, _NoCallbacks; | |
| 349 typedef _NotificationHandler(); | |
| 350 Future _runGuarded(_NotificationHandler notificationHandler) { | |
| 351 if (notificationHandler == null) return null; | |
| 352 try { | |
| 353 var result = notificationHandler(); | |
| 354 if (result is Future) return DDC$RT.cast(result, dynamic, | |
| 355 DDC$RT.type((Future<dynamic> _) {}), "CastGeneral", | |
| 356 """line 665, column 34 of dart:async/stream_controller.dart: """, | |
| 357 result is Future<dynamic>, true); | |
| 358 return null; | |
| 359 } catch (e, s) { | |
| 360 Zone.current.handleUncaughtError(e, s); | |
| 361 } | |
| 362 } | |
| 363 class _ControllerStream<T> extends _StreamImpl<T> { | |
| 364 _StreamControllerLifecycle<T> _controller; | |
| 365 _ControllerStream(this._controller); | |
| 366 StreamSubscription<T> _createSubscription(void onData(T data), | |
| 367 Function onError, void onDone(), bool cancelOnError) => | |
| 368 _controller._subscribe(onData, onError, onDone, cancelOnError); | |
| 369 int get hashCode => _controller.hashCode ^ 0x35323532; | |
| 370 bool operator ==(Object other) { | |
| 371 if (identical(this, other)) return true; | |
| 372 if (other is! _ControllerStream) return false; | |
| 373 _ControllerStream otherStream = DDC$RT.cast(other, Object, | |
| 374 DDC$RT.type((_ControllerStream<dynamic> _) {}), "CastGeneral", | |
| 375 """line 693, column 37 of dart:async/stream_controller.dart: """, | |
| 376 other is _ControllerStream<dynamic>, true); | |
| 377 return identical(otherStream._controller, this._controller); | |
| 378 } | |
| 379 } | |
| 380 class _ControllerSubscription<T> extends _BufferingStreamSubscription<T> { | |
| 381 final _StreamControllerLifecycle<T> _controller; | |
| 382 _ControllerSubscription(this._controller, void onData(T data), | |
| 383 Function onError, void onDone(), bool cancelOnError) | |
| 384 : super(onData, onError, onDone, cancelOnError); | |
| 385 Future _onCancel() { | |
| 386 return _controller._recordCancel(this); | |
| 387 } | |
| 388 void _onPause() { | |
| 389 _controller._recordPause(this); | |
| 390 } | |
| 391 void _onResume() { | |
| 392 _controller._recordResume(this); | |
| 393 } | |
| 394 } | |
| 395 class _StreamSinkWrapper<T> implements StreamSink<T> { | |
| 396 final StreamController _target; | |
| 397 _StreamSinkWrapper(this._target); | |
| 398 void add(T data) { | |
| 399 _target.add(data); | |
| 400 } | |
| 401 void addError(Object error, [StackTrace stackTrace]) { | |
| 402 _target.addError(error, stackTrace); | |
| 403 } | |
| 404 Future close() => _target.close(); | |
| 405 Future addStream(Stream<T> source, {bool cancelOnError: true}) => | |
| 406 _target.addStream(source, cancelOnError: cancelOnError); | |
| 407 Future get done => _target.done; | |
| 408 } | |
| 409 class _AddStreamState<T> { | |
| 410 final _Future addStreamFuture; | |
| 411 final StreamSubscription addSubscription; | |
| 412 _AddStreamState(_EventSink<T> controller, Stream source, bool cancelOnError) | |
| 413 : addStreamFuture = new _Future(), | |
| 414 addSubscription = source.listen(DDC$RT.wrap((void f(T __u93)) { | |
| 415 void c(T x0) => f(DDC$RT.cast(x0, dynamic, T, "CastParam", | |
| 416 """line 745, column 41 of dart:async/stream_controller.dart: """, | |
| 417 x0 is T, false)); | |
| 418 return f == null ? null : c; | |
| 419 }, controller._add, DDC$RT.type((__t96<T> _) {}), __t94, "Wrap", | |
| 420 """line 745, column 41 of dart:async/stream_controller.dart: """
, | |
| 421 controller._add is __t94), | |
| 422 onError: ((__x98) => DDC$RT.cast(__x98, dynamic, Function, | |
| 423 "CastGeneral", | |
| 424 """line 746, column 50 of dart:async/stream_controller.dart:
""", | |
| 425 __x98 is Function, true))(cancelOnError | |
| 426 ? makeErrorHandler(controller) | |
| 427 : controller._addError), | |
| 428 onDone: controller._close, | |
| 429 cancelOnError: cancelOnError); | |
| 430 static makeErrorHandler(_EventSink controller) => (e, StackTrace s) { | |
| 431 controller._addError(e, s); | |
| 432 controller._close(); | |
| 433 }; | |
| 434 void pause() { | |
| 435 addSubscription.pause(); | |
| 436 } | |
| 437 void resume() { | |
| 438 addSubscription.resume(); | |
| 439 } | |
| 440 Future cancel() { | |
| 441 var cancel = addSubscription.cancel(); | |
| 442 if (cancel == null) { | |
| 443 addStreamFuture._asyncComplete(null); | |
| 444 return null; | |
| 445 } | |
| 446 return cancel.whenComplete(() { | |
| 447 addStreamFuture._asyncComplete(null); | |
| 448 }); | |
| 449 } | |
| 450 void complete() { | |
| 451 addStreamFuture._asyncComplete(null); | |
| 452 } | |
| 453 } | |
| 454 class _StreamControllerAddStreamState<T> extends _AddStreamState<T> { | |
| 455 var varData; | |
| 456 _StreamControllerAddStreamState(_StreamController controller, this.varData, | |
| 457 Stream source, bool cancelOnError) | |
| 458 : super(DDC$RT.cast(controller, | |
| 459 DDC$RT.type((_StreamController<dynamic> _) {}), | |
| 460 DDC$RT.type((_EventSink<T> _) {}), "CastDynamic", | |
| 461 """line 798, column 15 of dart:async/stream_controller.dart: """, | |
| 462 controller is _EventSink<T>, false), source, cancelOnError) { | |
| 463 if (controller.isPaused) { | |
| 464 addSubscription.pause(); | |
| 465 } | |
| 466 } | |
| 467 } | |
| 468 typedef void __t94(dynamic __u95); | |
| 469 typedef void __t96<T>(T __u97); | |
| OLD | NEW |