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

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

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 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 | « packages/async/lib/src/result_future.dart ('k') | packages/async/lib/src/stream_completer.dart » ('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 import 'dart:async';
6
7 /// A transformer that converts a broadcast stream into a single-subscription
8 /// stream.
9 ///
10 /// This buffers the broadcast stream's events, which means that it starts
11 /// listening to a stream as soon as it's bound.
12 ///
13 /// This also casts the source stream's events to type `T`. If the cast fails,
14 /// the result stream will emit a [CastError]. This behavior is deprecated, and
15 /// should not be relied upon.
16 class SingleSubscriptionTransformer<S, T> implements StreamTransformer<S, T> {
17 const SingleSubscriptionTransformer();
18
19 Stream<T> bind(Stream<S> stream) {
20 var subscription;
21 var controller = new StreamController<T>(
22 sync: true, onCancel: () => subscription.cancel());
23 subscription = stream.listen((value) {
24 // TODO(nweiz): When we release a new major version, get rid of the second
25 // type parameter and avoid this conversion.
26 try {
27 controller.add(value as T);
28 } on CastError catch (error, stackTrace) {
29 controller.addError(error, stackTrace);
30 }
31 }, onError: controller.addError, onDone: controller.close);
32 return controller.stream;
33 }
34 }
OLDNEW
« no previous file with comments | « packages/async/lib/src/result_future.dart ('k') | packages/async/lib/src/stream_completer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698