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

Side by Side Diff: sdk/lib/core/sink.dart

Issue 12154006: Remove Sink and move CollectionSink to async. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove usage of Sink from pub. Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/corelib_sources.gypi ('k') | tests/lib/async/event_helper.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of dart.core;
6 /**
7 * An interface for an object that can receive a sequence of values.
8 */
9 abstract class Sink<T> {
10 /** Write a value to the sink. */
11 add(T value);
12 /** Tell the sink that no further values will be written. */
13 void close();
14 }
15
16 // ----------------------------------------------------------------------
17 // Collections/Sink interoperability
18 // ----------------------------------------------------------------------
19
20 typedef void _CollectionSinkCallback<T>(Collection<T> collection);
21
22 /** Sink that stores incoming data in a collection. */
23 class CollectionSink<T> implements Sink<T> {
24 final Collection<T> collection;
25 final _CollectionSinkCallback<T> callback;
26 bool _isClosed = false;
27
28 /**
29 * Create a sink that stores incoming values in a collection.
30 *
31 * The [collection] is the collection to add the values to.
32 *
33 * If [callback] is provided, then it's called with the collection as arugment
34 * when the sink's [close] method is called.
35 */
36 CollectionSink(this.collection, [void callback(Collection<T> collection)])
37 : this.callback = callback;
38
39 add(T value) {
40 if (_isClosed) throw new StateError("Adding to closed sink");
41 collection.add(value);
42 }
43
44 void close() {
45 if (_isClosed) throw new StateError("Closing closed sink");
46 _isClosed = true;
47 if (callback != null) callback(collection);
48 }
49 }
OLDNEW
« no previous file with comments | « sdk/lib/core/corelib_sources.gypi ('k') | tests/lib/async/event_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698