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

Unified Diff: sdk/lib/core/sink.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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
« no previous file with comments | « sdk/lib/core/set.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/sink.dart
diff --git a/sdk/lib/core/sink.dart b/sdk/lib/core/sink.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ef1c2aa686bc6e35d85270bba34b14c08e6192dd
--- /dev/null
+++ b/sdk/lib/core/sink.dart
@@ -0,0 +1,40 @@
+// Copyright (c) 2012, 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.
+
+/**
+ * An interface for an object that can receive a sequence of values.
+ */
+abstract class Sink<T> {
+ /** Write a value to the sink. */
+ add(T value);
+ /** Tell the sink that no further values will be written. */
+ void close();
+}
+
+// ----------------------------------------------------------------------
+// Collections/Sink interoperability
+// ----------------------------------------------------------------------
+
+typedef void _CollectionSinkCallback<T>(Collection<T> collection);
+
+/** Sink that stores incoming data in a collection. */
+class CollectionSink<T> implements Sink<T> {
+ final Collection<T> collection;
+ final _CollectionSinkCallback<T> callback;
+ bool _isClosed = false;
+
+ CollectionSink(this.collection, [void callback(Collection<T> collection)])
+ : this.callback = callback;
+
+ add(T value) {
+ if (_isClosed) throw new StateError("Adding to closed sink");
+ collection.add(value);
+ }
+
+ void close() {
+ if (_isClosed) throw new StateError("Closing closed sink");
+ _isClosed = true;
+ if (callback != null) callback(collection);
+ }
+}
« no previous file with comments | « sdk/lib/core/set.dart ('k') | sdk/lib/core/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698