felangel / bloc

A predictable state management library that helps implement the BLoC design pattern

Home Page:https://bloclibrary.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: ignore adding a new even if the bloc is closed

cyrax111 opened this issue · comments

Description

When we are adding an event to bloc it can be closed if so it will generate an exception. A bunch of adding events are following after async gap and at that moment the bloc can be closed.

What is the best practice to avoid the exceptions? Always check of closing state before adding an event?

Desired Solution

Ignore adding a new even if the bloc is closed.

Hi @cyrax111 👋
Thanks for opening an issue!

I recommend checking if a bloc has been closed before adding an event if the event is added asynchronously (this is similar to how StreamController works. Hope that helps 👍