| Index: pkg/glob/lib/src/stream_pool.dart
|
| diff --git a/pkg/barback/lib/src/utils/stream_pool.dart b/pkg/glob/lib/src/stream_pool.dart
|
| similarity index 88%
|
| copy from pkg/barback/lib/src/utils/stream_pool.dart
|
| copy to pkg/glob/lib/src/stream_pool.dart
|
| index 679672d2547e00db179138076efe7db2669345a2..641751333426d903d2f021515bd30a5fb6034225 100644
|
| --- a/pkg/barback/lib/src/utils/stream_pool.dart
|
| +++ b/pkg/glob/lib/src/stream_pool.dart
|
| @@ -2,7 +2,7 @@
|
| // 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.
|
|
|
| -library barback.utils.stream_pool;
|
| +library glob.stream_pool;
|
|
|
| import 'dart:async';
|
|
|
| @@ -16,6 +16,9 @@ class StreamPool<T> {
|
| /// Subscriptions to the streams that make up the pool.
|
| final _subscriptions = new Map<Stream<T>, StreamSubscription<T>>();
|
|
|
| + /// Whether this pool should be closed when it becomes empty.
|
| + bool _closeWhenEmpty = false;
|
| +
|
| /// Creates a new stream pool that only supports a single subscriber.
|
| ///
|
| /// Any events from broadcast streams in the pool will be buffered until a
|
| @@ -53,6 +56,7 @@ class StreamPool<T> {
|
| void remove(Stream<T> stream) {
|
| var subscription = _subscriptions.remove(stream);
|
| if (subscription != null) subscription.cancel();
|
| + if (_closeWhenEmpty && _subscriptions.isEmpty) close();
|
| }
|
|
|
| /// Removes all streams from this pool and closes [stream].
|
| @@ -63,4 +67,10 @@ class StreamPool<T> {
|
| _subscriptions.clear();
|
| _controller.close();
|
| }
|
| +
|
| + /// The next time this pool becomes empty, close it.
|
| + void closeWhenEmpty() {
|
| + if (_subscriptions.isEmpty) close();
|
| + _closeWhenEmpty = true;
|
| + }
|
| }
|
|
|