-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to SingleSubscriptionTransformer<S> #95
Comments
Not clear what should be changed. Can you elaborate? |
Sorry, I mistyped the name. This is a tracking issue for: async/lib/src/single_subscription_transformer.dart Lines 25 to 26 in f708371
This was never intended to be used in any way other than the case where both generics are the same. Concretely, this class should be defined as: /// A transformer that converts a broadcast stream into a single-subscription
/// stream.
///
/// This buffers the broadcast stream's events, which means that it starts
/// listening to a stream as soon as it's bound.
class SingleSubscriptionTransformer<S> extends StreamTransformerBase<S, S> {
const SingleSubscriptionTransformer();
@override
Stream<S> bind(Stream<S> stream) {
StreamSubscription<S> subscription;
var controller =
StreamController<S>(sync: true, onCancel: () => subscription.cancel());
subscription = stream.listen(controller.add,
onError: controller.addError, onDone: controller.close);
return controller.stream;
}
} |
Ack. FWIW, I'd implement it as: @override
Stream<S> bind(Stream<S> stream) {
var controller = StreamController<S>(sync: true);
controller.addStream(stream).whenComplete(controller.close);
return controller.stream;
} (I also think it's a bad idea to listen immediately and buffer an unboundend number of events, but if that's the desired semantics, I guess it has to happen). Let's make the Null Safe release a new major version, that should let us fix things like this. |
We really hope to be able to do that 😄 |
Currently its
SingleSubscriptionTransformer<S,T>
, but the purpose is not to allow changing the generic on the stream type. See TODO comment on in the file.The text was updated successfully, but these errors were encountered: