-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Possible regression with async* generator with dart 2.18.0 changes. Not yielding all events with yield*. #50379
Comments
In what environments are you hitting this? web? native? CC @lrhn – who likely has some context here! |
It shouldn't be possible to drop values. If there is a What might happen here is that the initial If There may also be other delays involved. Calling A possible workaround might be: Stream<T> createSeededStream<T>(T initialValue, Stream<T> stream) async* {
var c = StreamController<T>(sync: true);
stream.pipe(c).ignore(); // Buffer events happening until yield*
yield initialValue;
yield* c.stream; // Emit events of `stream`, buffered ones first.
} |
From my initial understanding/guess from the issue, that's what I thought happened. In our case, the initialization part of the stream remained the same. The behaviour just changed over night with 2.18.0. Which, could be the right behaviour now and used to be a bug as you said. Regardless, we have a fix now, I was mostly wondering if it was a caveat to have in mind when using async* with broadcast streams. |
Everything about broadcasts stream is a caveat. I'd go as far as saying: Don't use a broadcast stream if you can't accept losing some events. Even the delay between calling If you want to emit events to multiple listeners, but not necessarily the same events at the same time, I'd try using |
I am going ahead and close this issue given that it seems to have been answered. |
Environment details:
Before we were using Dart 2.17.6 with Flutter 3.0.5
Now we're using Dart 2.18.2 with Flutter 3.3.4.
Got this issue running tests using the dartvm. I haven't ran the test cases against web at that time.
Problem
Before dart 2.18.0 async* changes We were using this implementation to create a stream seeded with an initial value:
Which used to work fine for us. I believe we could get this to work fine for both Streams and BroadcastStreams. However since the 2.18.0 change, this implementation didn't work anymore. Our test cases started failing, dropping sometimes the initial value, sometimes the first values of the yielded stream.
We found that using this implementation fixes the issue, but I'm not quite sure why it's not working all the time anymore.
I believe the issue might lie in the fact that
stream
could be a broadcast stream, and that sometimes in a test environment the initial elements emitted in the stream are emitted too fast perhaps?I'm not sure how/where to go from here to help you figure out if there is a regression for real, but these were our observations.
cc: @kevmoo
The text was updated successfully, but these errors were encountered: