Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: sdk/lib/async/stream_transformers.dart

Issue 2822173002: Warn when adding something to a closed sink and improve documentation (Closed)
Patch Set: Improve documentation (issue 29122). Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ff2983ddae0cb11b665225b7c0dd6a2bf145b4e7 100644
--- a/sdk/lib/async/stream_transformers.dart
+++ b/sdk/lib/async/stream_transformers.dart
@@ -210,11 +210,13 @@ class _HandlerEventSink<S, T> implements EventSink<S> {
/// The output sink where the handlers should send their data into.
final EventSink<T> _sink;
Lasse Reichstein Nielsen 2017/04/26 08:26:19 Make this field non-final and set it to null when
floitsch 2017/05/01 16:46:25 Done.
+ bool _isClosed = false;
_HandlerEventSink(
this._handleData, this._handleError, this._handleDone, this._sink);
void add(S data) {
+ if (_isClosed) throw new StateError("Sink is closed");
if (_handleData != null) {
_handleData(data, _sink);
} else {
@@ -223,6 +225,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,6 +234,7 @@ class _HandlerEventSink<S, T> implements EventSink<S> {
}
void close() {
Lasse Reichstein Nielsen 2017/04/26 08:26:19 We should probably bail out here if the sink is al
floitsch 2017/05/01 16:46:25 Realized the same thing. done.
+ _isClosed = true;
if (_handleDone != null) {
_handleDone(_sink);
} else {

Powered by Google App Engine
This is Rietveld 408576698