Bloc: events are not running parallelly

Created on 10 Sep 2020  路  3Comments  路  Source: felangel/bloc

I have a page in that page I have 4 widget and for those 4 widget I have to make 4 api call(1 for each) so I have created the 4 event and I call the event. Event adding is working fine but execution of event is not happening paralleled 2nd event is executing only after first one get executed.

question

Most helpful comment

Future.wait returns the responses in form of a List<Object>, so you'd have something like:

final responses = await Future.wait([futures]);
final response1 = responses.first;
final response2 = responses[1];
...

Based on those you'd compose your state and yield it in mapEventToState.
Alternatively you could aggregate your requests in your repository layer and expose a single result, but that's up to you to decide what you need. 馃憤

All 3 comments

Hi @Virendra-Varma 馃憢

You could add a single event and make those requests using Future.wait([futures]) which will execute them parallelly.
Feel free to comment if that doesn't solve your issue. 馃憤

ok
and how would I yield the result

Future.wait returns the responses in form of a List<Object>, so you'd have something like:

final responses = await Future.wait([futures]);
final response1 = responses.first;
final response2 = responses[1];
...

Based on those you'd compose your state and yield it in mapEventToState.
Alternatively you could aggregate your requests in your repository layer and expose a single result, but that's up to you to decide what you need. 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rsnider19 picture rsnider19  路  3Comments

abinvp picture abinvp  路  3Comments

zjjt picture zjjt  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

frankrod picture frankrod  路  3Comments