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

Side by Side 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: Code review changes 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 unified diff | Download patch
« no previous file with comments | « lib/convert.dart ('k') | lib/src/byte_accumulator_sink.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) 2016, 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 import 'dart:collection';
6
7 /// A sink that provides access to all the [events] that have been passed to it.
8 ///
9 /// See also [ChunkedConversionSink.withCallback].
10 class AccumulatorSink<T> implements Sink<T> {
11 /// An unmodifiable list of events passed to this sink so far.
12 List<T> get events => new UnmodifiableListView(_events);
13 final _events = <T>[];
14
15 /// Whether [close] has been called.
16 bool get isClosed => _isClosed;
17 var _isClosed = false;
18
19 /// Removes all events from [events].
20 ///
21 /// This can be used to avoid double-processing events.
22 void clear() {
23 _events.clear();
24 }
25
26 void add(T event) {
27 if (_isClosed) {
28 throw new StateError("Can't add to a closed sink.");
29 }
30
31 _events.add(event);
32 }
33
34 void close() {
35 _isClosed = true;
36 }
37 }
OLDNEW
« no previous file with comments | « lib/convert.dart ('k') | lib/src/byte_accumulator_sink.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698