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..d6a065503bf586db2bf84ed3e018c5500b058464 100644 |
--- a/sdk/lib/async/stream_transformers.dart |
+++ b/sdk/lib/async/stream_transformers.dart |
@@ -209,12 +209,19 @@ 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) throw new StateError("Sink is closed"); |
if (_handleData != null) { |
_handleData(data, _sink); |
} else { |
@@ -223,6 +230,7 @@ class _HandlerEventSink<S, T> implements EventSink<S> { |
} |
void addError(Object error, [StackTrace stackTrace]) { |
+ if (_isClosed) throw new StateError("Sink is closed"); |
if (_handleError != null) { |
_handleError(error, stackTrace, _sink); |
} else { |
@@ -231,10 +239,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(); |
} |
} |
} |