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

Side by Side Diff: lib/src/single_subscription_transformer.dart

Issue 1584023002: Add SingleSubscriptionTransformer. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Update pubspec Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « lib/async.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library async.single_subscription_transformer;
6
7 import 'dart:async';
8
9 /// A transformer that converts a broadcast stream into a single-subscription
10 /// stream.
11 ///
12 /// This buffers the broadcast stream's events, which means that it starts
13 /// listening to a stream as soon as it's bound.
14 class SingleSubscriptionTransformer<S, T> implements StreamTransformer<S, T> {
15 const SingleSubscriptionTransformer();
16
17 Stream<T> bind(Stream<S> stream) {
18 var subscription;
19 var controller = new StreamController(sync: true,
20 onCancel: () => subscription.cancel());
21 subscription = stream.listen(controller.add,
22 onError: controller.addError, onDone: controller.close);
23 return controller.stream;
24 }
25 }
OLDNEW
« no previous file with comments | « lib/async.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698