OLD | NEW |
---|---|
(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 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.
| |
8 /// passed to it. | |
9 class AccumulatorSink<T> implements Sink<T> { | |
10 /// An unmodifiable list of events passed to this sink so far. | |
11 List<T> get events => new UnmodifiableListView(_events); | |
12 final _events = <T>[]; | |
13 | |
14 /// Whether [close] has been called. | |
15 bool get isClosed => _isClosed; | |
16 var _isClosed = false; | |
17 | |
18 void add(T event) { | |
19 if (_isClosed) { | |
20 throw new StateError("Can't add to a closed sink."); | |
21 } | |
22 | |
23 _events.add(event); | |
24 } | |
25 | |
26 void close() { | |
27 _isClosed = true; | |
28 } | |
29 } | |
OLD | NEW |