| 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;
|
| +}
|
|
|