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

Unified 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, 9 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 | « lib/src/result/value.dart ('k') | lib/src/stream_completer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/single_subscription_transformer.dart
diff --git a/lib/src/single_subscription_transformer.dart b/lib/src/single_subscription_transformer.dart
index 4255175f5d797a68111b5c3f978d515ce821c263..e01efac0041095e0d5d31e746bb1a3ef9bbfbfca 100644
--- a/lib/src/single_subscription_transformer.dart
+++ b/lib/src/single_subscription_transformer.dart
@@ -9,15 +9,26 @@ import 'dart:async';
///
/// This buffers the broadcast stream's events, which means that it starts
/// listening to a stream as soon as it's bound.
+///
+/// This also casts the source stream's events to type `T`. If the cast fails,
+/// the result stream will emit a [CastError]. This behavior is deprecated, and
+/// should not be relied upon.
class SingleSubscriptionTransformer<S, T> implements StreamTransformer<S, T> {
const SingleSubscriptionTransformer();
Stream<T> bind(Stream<S> stream) {
var subscription;
- var controller = new StreamController(sync: true,
+ var controller = new StreamController<T>(sync: true,
onCancel: () => subscription.cancel());
- subscription = stream.listen(controller.add,
- onError: controller.addError, onDone: controller.close);
+ subscription = stream.listen((value) {
+ // TODO(nweiz): When we release a new major version, get rid of the second
+ // type parameter and avoid this conversion.
+ try {
+ controller.add(value as T);
+ } on CastError catch (error, stackTrace) {
+ controller.addError(error, stackTrace);
+ }
+ }, onError: controller.addError, onDone: controller.close);
return controller.stream;
}
}
« 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