-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
fix: forEach emits new states, after event handler canceled. #3586
Comments
@thipokch in your DemoBloc, you are using refer to this #3623 (comment) change this: on<EventB>(
(event, emit) =>
emit.forEach(source.numbers, onData: (data) => StateB()),
transformer: restartable());
to this: on<EventB>((event, emit) async {
await emit.forEach(source.numbers, onData: (data) => StateB())
},
transformer: restartable());
|
@jacobtipp Thanks! |
@jacobtipp @felangel @thipokch This does not work |
@vasilich6107 can you share a link to a minimal reproduction sample? From the screenshot it looks like you’re bucketing EventA and EventB separately so they won’t interfere with each other. I’m guessing you want to bucket them together instead: on<DemoEvent>((event, emit) async {
if (event is EventA) {…}
else if (event is EventB) {…}
}, transformer: restartable()); |
hi @felangel |
See my updated comment and let me know if that helps. |
@felangel this was not my code) I do not know why author closed it as far as suggested approach does not fix the issue. I will try to find time and create my own example |
Thanks for the context above all! Just trying to fix an issue myself where I want to stop listening to a stream that I started listening to with emit.ForEach. I tried restartable but that didn't work. The UI dispatches another event, and I want it to stop subscription there. Is this possible? |
@vasilich6107 thank you! will keep an eye out there. I think my problem may have been that I instantiate multiple instances of the same provider. I need this because I want each child widget in a column of widgets to have their own provider. For some reason though, there is a clash and when one of the items in the list of widgets disposes and I call .close, it still continues to listen to the stream that was passed in. (i.e. emit.forEach doesn't stop listening to stream when the provider is closed.) |
Description / Expected Behavior
When a new event with
restartable()
is added to a bloc, it is expected that ongoing asynchronous event will be canceled . However, it appears thatemit.forEach
within the same event is still emitting new states when it should be closed.Steps To Reproduce
1. Create the following bloc.
2. Create following the bloc test
3. Run tests
demo.zip
Additional Context
I'm a little unsure how concurrency transforms interact with each other. Here's the potential use case.
The text was updated successfully, but these errors were encountered: