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

Unified Diff: lib/src/accumulator_sink.dart

Issue 1911053002: Add sinks to provide synchronous access to events. (Closed) Base URL: git@github.com:dart-lang/convert@master
Patch Set: Created 4 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: lib/src/accumulator_sink.dart
diff --git a/lib/src/accumulator_sink.dart b/lib/src/accumulator_sink.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c7fb44571da23ee757bf1e416d65355e6468f72f
--- /dev/null
+++ b/lib/src/accumulator_sink.dart
@@ -0,0 +1,29 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:collection';
+
+/// A sink that provides synchronous access to all the [events] that have been
Lasse Reichstein Nielsen 2016/04/22 09:15:13 Drop the "synchronous".
nweiz 2016/04/22 21:19:55 Done.
+/// passed to it.
+class AccumulatorSink<T> implements Sink<T> {
+ /// An unmodifiable list of events passed to this sink so far.
+ List<T> get events => new UnmodifiableListView(_events);
+ final _events = <T>[];
+
+ /// Whether [close] has been called.
+ bool get isClosed => _isClosed;
+ var _isClosed = false;
+
+ void add(T event) {
+ if (_isClosed) {
+ throw new StateError("Can't add to a closed sink.");
+ }
+
+ _events.add(event);
+ }
+
+ void close() {
+ _isClosed = true;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698