| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 7 /** |
| 8 * Wraps an [_EventSink] so it exposes only the [EventSink] interface. | 8 * Wraps an [_EventSink] so it exposes only the [EventSink] interface. |
| 9 */ | 9 */ |
| 10 class _EventSinkWrapper<T> implements EventSink<T> { | 10 class _EventSinkWrapper<T> implements EventSink<T> { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class _SinkTransformerStreamSubscription<S, T> | 28 class _SinkTransformerStreamSubscription<S, T> |
| 29 extends _BufferingStreamSubscription<T> { | 29 extends _BufferingStreamSubscription<T> { |
| 30 /// The transformer's input sink. | 30 /// The transformer's input sink. |
| 31 EventSink _transformerSink; | 31 EventSink _transformerSink; |
| 32 | 32 |
| 33 /// The subscription to the input stream. | 33 /// The subscription to the input stream. |
| 34 StreamSubscription<S> _subscription; | 34 StreamSubscription<S> _subscription; |
| 35 | 35 |
| 36 _SinkTransformerStreamSubscription(Stream<S> source, | 36 _SinkTransformerStreamSubscription(Stream<S> source, |
| 37 _SinkMapper mapper, | 37 _SinkMapper mapper, |
| 38 void onData(T data), |
| 39 Function onError, |
| 40 void onDone(), |
| 38 bool cancelOnError) | 41 bool cancelOnError) |
| 39 // We set the adapter's target only when the user is allowed to send data. | 42 // We set the adapter's target only when the user is allowed to send data. |
| 40 : super(cancelOnError) { | 43 : super(onData, onError, onDone, cancelOnError) { |
| 41 _EventSinkWrapper<T> eventSink = new _EventSinkWrapper<T>(this); | 44 _EventSinkWrapper<T> eventSink = new _EventSinkWrapper<T>(this); |
| 42 _transformerSink = mapper(eventSink); | 45 _transformerSink = mapper(eventSink); |
| 43 _subscription = source.listen(_handleData, | 46 _subscription = source.listen(_handleData, |
| 44 onError: _handleError, | 47 onError: _handleError, |
| 45 onDone: _handleDone); | 48 onDone: _handleDone); |
| 46 } | 49 } |
| 47 | 50 |
| 48 /** Whether this subscription is still subscribed to its source. */ | 51 /** Whether this subscription is still subscribed to its source. */ |
| 49 bool get _isSubscribed => _subscription != null; | 52 bool get _isSubscribed => _subscription != null; |
| 50 | 53 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 bool get isBroadcast => _stream.isBroadcast; | 177 bool get isBroadcast => _stream.isBroadcast; |
| 175 | 178 |
| 176 _BoundSinkStream(this._stream, this._sinkMapper); | 179 _BoundSinkStream(this._stream, this._sinkMapper); |
| 177 | 180 |
| 178 StreamSubscription<T> listen(void onData(T event), | 181 StreamSubscription<T> listen(void onData(T event), |
| 179 { Function onError, | 182 { Function onError, |
| 180 void onDone(), | 183 void onDone(), |
| 181 bool cancelOnError }) { | 184 bool cancelOnError }) { |
| 182 cancelOnError = identical(true, cancelOnError); | 185 cancelOnError = identical(true, cancelOnError); |
| 183 StreamSubscription<T> subscription = new _SinkTransformerStreamSubscription( | 186 StreamSubscription<T> subscription = new _SinkTransformerStreamSubscription( |
| 184 _stream, _sinkMapper, cancelOnError); | 187 _stream, _sinkMapper, onData, onError, onDone, cancelOnError); |
| 185 subscription.onData(onData); | |
| 186 subscription.onError(onError); | |
| 187 subscription.onDone(onDone); | |
| 188 return subscription; | 188 return subscription; |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 /// Data-handler coming from [StreamTransformer.fromHandlers]. | 192 /// Data-handler coming from [StreamTransformer.fromHandlers]. |
| 193 typedef void _TransformDataHandler<S, T>(S data, EventSink<T> sink); | 193 typedef void _TransformDataHandler<S, T>(S data, EventSink<T> sink); |
| 194 /// Error-handler coming from [StreamTransformer.fromHandlers]. | 194 /// Error-handler coming from [StreamTransformer.fromHandlers]. |
| 195 typedef void _TransformErrorHandler<T>( | 195 typedef void _TransformErrorHandler<T>( |
| 196 Object error, StackTrace stackTrace, EventSink<T> sink); | 196 Object error, StackTrace stackTrace, EventSink<T> sink); |
| 197 /// Done-handler coming from [StreamTransformer.fromHandlers]. | 197 /// Done-handler coming from [StreamTransformer.fromHandlers]. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 void onDone(), | 302 void onDone(), |
| 303 bool cancelOnError }) { | 303 bool cancelOnError }) { |
| 304 cancelOnError = identical(true, cancelOnError); | 304 cancelOnError = identical(true, cancelOnError); |
| 305 StreamSubscription<T> result = _transformer(_stream, cancelOnError); | 305 StreamSubscription<T> result = _transformer(_stream, cancelOnError); |
| 306 result.onData(onData); | 306 result.onData(onData); |
| 307 result.onError(onError); | 307 result.onError(onError); |
| 308 result.onDone(onDone); | 308 result.onDone(onDone); |
| 309 return result; | 309 return result; |
| 310 } | 310 } |
| 311 } | 311 } |
| OLD | NEW |