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

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

Issue 262173009: Add aggregate transformer types to barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 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/barback/lib/src/transformer/transform.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/utils.dart
diff --git a/pkg/barback/lib/src/utils.dart b/pkg/barback/lib/src/utils.dart
index d2ce0495130b728187dd9e26d5247766e91a206f..d5a9fb62dd1130684c73390fd2904d7f7ccafbff 100644
--- a/pkg/barback/lib/src/utils.dart
+++ b/pkg/barback/lib/src/utils.dart
@@ -308,3 +308,20 @@ Stream callbackStream(Stream callback()) {
sync: true);
return controller.stream;
}
+
+/// Creates a single-subscription stream from a broadcast stream.
+///
+/// The returned stream will enqueue events from [broadcast] until a listener is
+/// attached, then pipe events to that listener.
+Stream broadcastToSingleSubscription(Stream broadcast) {
+ if (!broadcast.isBroadcast) return broadcast;
+
+ // TODO(nweiz): Implement this using a transformer when issues 18588 and 18586
+ // are fixed.
+ var subscription;
+ var controller = new StreamController(onCancel: () => subscription.cancel());
+ subscription = broadcast.listen(controller.add,
+ onError: controller.addError,
+ onDone: controller.close);
+ return controller.stream;
+}
« no previous file with comments | « pkg/barback/lib/src/transformer/transform.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698