| 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.convert; | 5 part of dart.convert; |
| 6 | 6 |
| 7 typedef void _ChunkedConversionCallback<T>(T accumulated); | 7 typedef void _ChunkedConversionCallback<T>(T accumulated); |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * A [ChunkedConversionSink] is used to transmit data more efficiently between | 10 * A [ChunkedConversionSink] is used to transmit data more efficiently between |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 _ConverterStreamEventTransformer<S, T> eventTransformer) | 63 _ConverterStreamEventTransformer<S, T> eventTransformer) |
| 64 : _eventTransformer = eventTransformer, | 64 : _eventTransformer = eventTransformer, |
| 65 super(source, eventTransformer); | 65 super(source, eventTransformer); |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Starts listening to `this`. | 68 * Starts listening to `this`. |
| 69 * | 69 * |
| 70 * This starts the chunked conversion. | 70 * This starts the chunked conversion. |
| 71 */ | 71 */ |
| 72 StreamSubscription<T> listen(void onData(T data), | 72 StreamSubscription<T> listen(void onData(T data), |
| 73 { void onError(error), | 73 { Function onError, |
| 74 void onDone(), | 74 void onDone(), |
| 75 bool cancelOnError }) { | 75 bool cancelOnError }) { |
| 76 _eventTransformer._startChunkedConversion(); | 76 _eventTransformer._startChunkedConversion(); |
| 77 return super.listen(onData, onError: onError, onDone: onDone, | 77 return super.listen(onData, onError: onError, onDone: onDone, |
| 78 cancelOnError: cancelOnError); | 78 cancelOnError: cancelOnError); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * This class converts implements the logic for a chunked conversion as a | 83 * This class converts implements the logic for a chunked conversion as a |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 118 } |
| 119 | 119 |
| 120 void add(T o) => _eventSink.add(o); | 120 void add(T o) => _eventSink.add(o); |
| 121 void close() => _eventSink.close(); | 121 void close() => _eventSink.close(); |
| 122 | 122 |
| 123 void handleData(S event, EventSink<T> eventSink) { | 123 void handleData(S event, EventSink<T> eventSink) { |
| 124 _eventSink = eventSink; | 124 _eventSink = eventSink; |
| 125 try { | 125 try { |
| 126 _chunkedSink.add(event); | 126 _chunkedSink.add(event); |
| 127 } catch(e) { | 127 } catch(e) { |
| 128 // TODO(floitsch): capture stack trace. |
| 128 eventSink.addError(e); | 129 eventSink.addError(e); |
| 129 } finally { | 130 } finally { |
| 130 _eventSink = null; | 131 _eventSink = null; |
| 131 } | 132 } |
| 132 } | 133 } |
| 133 | 134 |
| 134 void handleDone(EventSink<T> eventSink) { | 135 void handleDone(EventSink<T> eventSink) { |
| 135 _eventSink = eventSink; | 136 _eventSink = eventSink; |
| 136 try { | 137 try { |
| 137 _chunkedSink.close(); | 138 _chunkedSink.close(); |
| 138 } catch(e) { | 139 } catch(e) { |
| 140 // TODO(floitsch): capture stack trace. |
| 139 eventSink.addError(e); | 141 eventSink.addError(e); |
| 140 } finally { | 142 } finally { |
| 141 _eventSink = null; | 143 _eventSink = null; |
| 142 } | 144 } |
| 143 } | 145 } |
| 144 | 146 |
| 145 void handleError(var errorEvent, EventSink<T> eventSink) { | 147 void handleError(var errorEvent, EventSink<T> eventSink) { |
| 148 // TODO(floitsch): capture stack trace. |
| 146 eventSink.addError(errorEvent); | 149 eventSink.addError(errorEvent); |
| 147 } | 150 } |
| 148 } | 151 } |
| OLD | NEW |