| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.async; | 5 part of dart.async; |
| 6 | 6 |
| 7 typedef void _CollectionSinkCallback<T>(Collection<T> collection); | 7 typedef void _CollectionSinkCallback<T>(Collection<T> collection); |
| 8 typedef void _CollectionSinkErrorCallback(AsyncError error); | 8 typedef void _CollectionSinkErrorCallback(AsyncError error); |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * EventSink that stores incoming data in a collection. | 11 * EventSink that stores incoming data in a collection. |
| 12 * | 12 * |
| 13 * *Deprecated*. | 13 * *Deprecated*. |
| 14 */ | 14 */ |
| 15 class CollectionSink<T> extends StreamSink<T> { | 15 class CollectionSink<T> extends EventSink<T> { |
| 16 // TODO(8997): Implement EventSink instead. | 16 // TODO(8997): Implement EventSink instead. |
| 17 final Collection<T> collection; | 17 final Collection<T> collection; |
| 18 final _CollectionSinkCallback<T> _callback; | 18 final _CollectionSinkCallback<T> _callback; |
| 19 final _CollectionSinkErrorCallback _errorCallback; | 19 final _CollectionSinkErrorCallback _errorCallback; |
| 20 bool _isClosed = false; | 20 bool _isClosed = false; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Create a sink that stores incoming values in a collection. | 23 * Create a sink that stores incoming values in a collection. |
| 24 * | 24 * |
| 25 * The [collection] is the collection to add the values to. | 25 * The [collection] is the collection to add the values to. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 42 if (_isClosed) throw new StateError("Adding error to closed sink"); | 42 if (_isClosed) throw new StateError("Adding error to closed sink"); |
| 43 if (_errorCallback != null) _errorCallback(error); | 43 if (_errorCallback != null) _errorCallback(error); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void close() { | 46 void close() { |
| 47 if (_isClosed) throw new StateError("Closing closed sink"); | 47 if (_isClosed) throw new StateError("Closing closed sink"); |
| 48 _isClosed = true; | 48 _isClosed = true; |
| 49 if (_callback != null) _callback(collection); | 49 if (_callback != null) _callback(collection); |
| 50 } | 50 } |
| 51 } | 51 } |
| OLD | NEW |