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

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

Issue 1841223002: Fix most strong mode warnings. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Code review changes Created 4 years, 8 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/src/result/value.dart ('k') | 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
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 /// A transformer that converts a broadcast stream into a single-subscription 7 /// A transformer that converts a broadcast stream into a single-subscription
8 /// stream. 8 /// stream.
9 /// 9 ///
10 /// This buffers the broadcast stream's events, which means that it starts 10 /// This buffers the broadcast stream's events, which means that it starts
11 /// listening to a stream as soon as it's bound. 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.
12 class SingleSubscriptionTransformer<S, T> implements StreamTransformer<S, T> { 16 class SingleSubscriptionTransformer<S, T> implements StreamTransformer<S, T> {
13 const SingleSubscriptionTransformer(); 17 const SingleSubscriptionTransformer();
14 18
15 Stream<T> bind(Stream<S> stream) { 19 Stream<T> bind(Stream<S> stream) {
16 var subscription; 20 var subscription;
17 var controller = new StreamController(sync: true, 21 var controller = new StreamController<T>(sync: true,
18 onCancel: () => subscription.cancel()); 22 onCancel: () => subscription.cancel());
19 subscription = stream.listen(controller.add, 23 subscription = stream.listen((value) {
20 onError: controller.addError, onDone: controller.close); 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);
21 return controller.stream; 32 return controller.stream;
22 } 33 }
23 } 34 }
OLDNEW
« no previous file with comments | « lib/src/result/value.dart ('k') | lib/src/stream_completer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698