| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 _HandlerEventSink( | 214 _HandlerEventSink( |
| 215 this._handleData, this._handleError, this._handleDone, this._sink) { | 215 this._handleData, this._handleError, this._handleDone, this._sink) { |
| 216 if (_sink == null) { | 216 if (_sink == null) { |
| 217 throw new ArgumentError("The provided sink must not be null."); | 217 throw new ArgumentError("The provided sink must not be null."); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 bool get _isClosed => _sink == null; | 221 bool get _isClosed => _sink == null; |
| 222 | 222 |
| 223 _reportClosedSink() { | |
| 224 // TODO(29554): throw a StateError, and don't just report the problem. | |
| 225 Zone.ROOT | |
| 226 ..print("Sink is closed and adding to it is an error.") | |
| 227 ..print(" See http://dartbug.com/29554.") | |
| 228 ..print(StackTrace.current.toString()); | |
| 229 } | |
| 230 | |
| 231 void add(S data) { | 223 void add(S data) { |
| 232 if (_isClosed) { | 224 if (_isClosed) { |
| 233 _reportClosedSink(); | 225 throw new StateError("Sink is closed"); |
| 234 } | 226 } |
| 235 if (_handleData != null) { | 227 if (_handleData != null) { |
| 236 _handleData(data, _sink); | 228 _handleData(data, _sink); |
| 237 } else { | 229 } else { |
| 238 _sink.add(data as T); | 230 _sink.add(data as T); |
| 239 } | 231 } |
| 240 } | 232 } |
| 241 | 233 |
| 242 void addError(Object error, [StackTrace stackTrace]) { | 234 void addError(Object error, [StackTrace stackTrace]) { |
| 243 if (_isClosed) { | 235 if (_isClosed) { |
| 244 _reportClosedSink(); | 236 throw new StateError("Sink is closed"); |
| 245 } | 237 } |
| 246 if (_handleError != null) { | 238 if (_handleError != null) { |
| 247 _handleError(error, stackTrace, _sink); | 239 _handleError(error, stackTrace, _sink); |
| 248 } else { | 240 } else { |
| 249 _sink.addError(error, stackTrace); | 241 _sink.addError(error, stackTrace); |
| 250 } | 242 } |
| 251 } | 243 } |
| 252 | 244 |
| 253 void close() { | 245 void close() { |
| 254 if (_isClosed) return; | 246 if (_isClosed) return; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 StreamSubscription<T> listen(void onData(T event), | 315 StreamSubscription<T> listen(void onData(T event), |
| 324 {Function onError, void onDone(), bool cancelOnError}) { | 316 {Function onError, void onDone(), bool cancelOnError}) { |
| 325 cancelOnError = identical(true, cancelOnError); | 317 cancelOnError = identical(true, cancelOnError); |
| 326 StreamSubscription<T> result = _onListen(_stream, cancelOnError); | 318 StreamSubscription<T> result = _onListen(_stream, cancelOnError); |
| 327 result.onData(onData); | 319 result.onData(onData); |
| 328 result.onError(onError); | 320 result.onError(onError); |
| 329 result.onDone(onDone); | 321 result.onDone(onDone); |
| 330 return result; | 322 return result; |
| 331 } | 323 } |
| 332 } | 324 } |
| OLD | NEW |