Chromium Code Reviews| Index: sdk/lib/async/stream_transformers.dart |
| diff --git a/sdk/lib/async/stream_transformers.dart b/sdk/lib/async/stream_transformers.dart |
| index bfc83d6b58b4befbe215bd641956492567b85380..8eb06f75b8e51b801262296ed6886fe1c6b1f192 100644 |
| --- a/sdk/lib/async/stream_transformers.dart |
| +++ b/sdk/lib/async/stream_transformers.dart |
| @@ -209,12 +209,24 @@ class _HandlerEventSink<S, T> implements EventSink<S> { |
| final _TransformDoneHandler<T> _handleDone; |
| /// The output sink where the handlers should send their data into. |
| - final EventSink<T> _sink; |
| + EventSink<T> _sink; |
| _HandlerEventSink( |
| - this._handleData, this._handleError, this._handleDone, this._sink); |
| + this._handleData, this._handleError, this._handleDone, this._sink) { |
| + if (_sink == null) { |
| + throw new ArgumentError("The provided sink must not be null."); |
| + } |
| + } |
| + |
| + bool get _isClosed => _sink == null; |
| void add(S data) { |
| + if (_isClosed) { |
| + // TODO(29554): throw a StateError, and don't just report the problem. |
| + Zone.ROOT.print("Sink is closed and adding to it is an error."); |
| + Zone.ROOT.print(" See http://dartbug.com/29554."); |
|
Lasse Reichstein Nielsen
2017/05/08 11:31:08
Cascade?
floitsch
2017/05/08 12:22:39
Done.
|
| + Zone.ROOT.print(StackTrace.current); |
|
Lasse Reichstein Nielsen
2017/05/08 11:31:08
Consider returning here. Adding isn't useful. Ditt
floitsch
2017/05/08 12:22:39
The whole point of the warning is to keep the old
|
| + } |
| if (_handleData != null) { |
| _handleData(data, _sink); |
| } else { |
| @@ -223,6 +235,12 @@ class _HandlerEventSink<S, T> implements EventSink<S> { |
| } |
| void addError(Object error, [StackTrace stackTrace]) { |
| + if (_isClosed) { |
| + // TODO(29554): throw a StateError, and don't just report the problem. |
| + Zone.ROOT.print("Sink is closed and adding to it is an error."); |
| + Zone.ROOT.print(" See http://dartbug.com/29554."); |
| + Zone.ROOT.print(StackTrace.current); |
| + } |
| if (_handleError != null) { |
| _handleError(error, stackTrace, _sink); |
| } else { |
| @@ -231,10 +249,13 @@ class _HandlerEventSink<S, T> implements EventSink<S> { |
| } |
| void close() { |
| + if (_isClosed) return; |
| + var sink = _sink; |
| + _sink = null; |
| if (_handleDone != null) { |
| - _handleDone(_sink); |
| + _handleDone(sink); |
| } else { |
| - _sink.close(); |
| + sink.close(); |
| } |
| } |
| } |