bloc dispatch delay

Created on 16 Sep 2019  路  3Comments  路  Source: felangel/bloc

Hi there,

I am using bloc to send events throughout my app after reading RFID tags from a hardware device. I'm not sure why, but it seems it takes an incredibly long time from the event dispatch, till the maptostate function is called.
the delayed dispatch events cause a problem in my app, because they arrive in my bloc, after the state of the application has already changed.
Is it possible to clear all events that are in the "queue" of a bloc from the view?

question

Most helpful comment

perfect, thanks!

All 3 comments

ok I think I understand now, in mapEventToState, the end of the stream needs to be reached, for the next mapEventToState to be triggered, right?

Hi @Freundschaft 馃憢
Thanks for opening an issue!

Yes, by default, a bloc will only start processing the next event once the current event has been processed. You can change this behavior by overriding transformEvents like so:

@override
Stream<State> transformEvents(events, next) {
  return (events as Observable<Event>).switchMap(next);
}

This will tell the bloc to stop processing old events whenever a new event is received. Hope that helps 馃憤

perfect, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zjjt picture zjjt  路  3Comments

abinvp picture abinvp  路  3Comments

clicksocial picture clicksocial  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

rsnider19 picture rsnider19  路  3Comments