MRazaImtiaz
MRazaImtiaz

Reputation: 2187

Run two network call in parallel (synchronous) and get their result to compare before moving to next code in flutter mobile

Fallowing code include two Network Request which is running Asynchronous, I want to run them parallel and get their result to compare before moving to next code.

 final failureOrGovernate = await getGovernateDataUsecase();
  
 final failureOrArea = await getAreaDataUsecase();

Thank You, your comments and answers are highly appreciated.

Upvotes: 1

Views: 144

Answers (1)

Gazihan Alankus
Gazihan Alankus

Reputation: 11994

You can wait on multiple futures in parallel with Future.wait()

final both = await Future.wait([getGovernateDataUsecase(), getAreaDataUsecase()]);

final failureOrGovernate = both[0];
final failureOrArea = both[1];

Upvotes: 5

Related Questions