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