Created
April 10, 2019 08:18
-
-
Save minikin/40d91f3d1a9bb68e477e9510b70a6acf to your computer and use it in GitHub Desktop.
Parallel networking calls in Dart 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
Stream<OrderDetailsState> mapEventToState( | |
OrderDetailsEvent event, | |
) async* { | |
if (event is ShowOrderDetails) { | |
yield OrderDetailsState.loading(); | |
try { | |
final account = await _authRepository.refreshToken(); | |
final results = await Future.wait( | |
[ | |
_ordersRepository.fetchQuestionnaire( | |
id: event.id, | |
account: account, | |
), | |
_ordersRepository.fetchMeta( | |
id: event.id, | |
account: account, | |
) | |
], | |
); | |
yield OrderDetailsState.success(results[0], results[1]); | |
} catch (error) { | |
yield OrderDetailsState.failure(error.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment