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

Unified Diff: pkg/barback/lib/src/utils/stream_pool.dart

Issue 808713003: Remove barback from the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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/barback/lib/src/utils/multiset.dart ('k') | pkg/barback/lib/src/utils/stream_replayer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/utils/stream_pool.dart
diff --git a/pkg/barback/lib/src/utils/stream_pool.dart b/pkg/barback/lib/src/utils/stream_pool.dart
deleted file mode 100644
index 679672d2547e00db179138076efe7db2669345a2..0000000000000000000000000000000000000000
--- a/pkg/barback/lib/src/utils/stream_pool.dart
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
-// 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;
-
-import 'dart:async';
-
-/// A pool of streams whose events are unified and emitted through a central
-/// stream.
-class StreamPool<T> {
- /// The stream through which all events from streams in the pool are emitted.
- Stream<T> get stream => _controller.stream;
- final StreamController<T> _controller;
-
- /// Subscriptions to the streams that make up the pool.
- final _subscriptions = new Map<Stream<T>, StreamSubscription<T>>();
-
- /// Creates a new stream pool that only supports a single subscriber.
- ///
- /// Any events from broadcast streams in the pool will be buffered until a
- /// listener is subscribed.
- StreamPool()
- // Create the controller as sync so that any sync input streams will be
- // forwarded synchronously. Async input streams will have their asynchrony
- // preserved, since _controller.add will be called asynchronously.
- : _controller = new StreamController<T>(sync: true);
-
- /// Creates a new stream pool where [stream] can be listened to more than
- /// once.
- ///
- /// Any events from buffered streams in the pool will be emitted immediately,
- /// regardless of whether [stream] has any subscribers.
- StreamPool.broadcast()
- // Create the controller as sync so that any sync input streams will be
- // forwarded synchronously. Async input streams will have their asynchrony
- // preserved, since _controller.add will be called asynchronously.
- : _controller = new StreamController<T>.broadcast(sync: true);
-
- /// Adds [stream] as a member of this pool.
- ///
- /// Any events from [stream] will be emitted through [this.stream]. If
- /// [stream] is sync, they'll be emitted synchronously; if [stream] is async,
- /// they'll be emitted asynchronously.
- void add(Stream<T> stream) {
- if (_subscriptions.containsKey(stream)) return;
- _subscriptions[stream] = stream.listen(_controller.add,
- onError: _controller.addError,
- onDone: () => remove(stream));
- }
-
- /// Removes [stream] as a member of this pool.
- void remove(Stream<T> stream) {
- var subscription = _subscriptions.remove(stream);
- if (subscription != null) subscription.cancel();
- }
-
- /// Removes all streams from this pool and closes [stream].
- void close() {
- for (var subscription in _subscriptions.values) {
- subscription.cancel();
- }
- _subscriptions.clear();
- _controller.close();
- }
-}
« no previous file with comments | « pkg/barback/lib/src/utils/multiset.dart ('k') | pkg/barback/lib/src/utils/stream_replayer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698