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

Unified Diff: pkg/glob/lib/src/stream_pool.dart

Issue 549633002: Add support for listing to the glob package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/glob/lib/src/list_tree.dart ('k') | pkg/glob/lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+ }
}
« no previous file with comments | « pkg/glob/lib/src/list_tree.dart ('k') | pkg/glob/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698