Skip to content

Instantly share code, notes, and snippets.

@minikin
Created April 10, 2019 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minikin/40d91f3d1a9bb68e477e9510b70a6acf to your computer and use it in GitHub Desktop.
Save minikin/40d91f3d1a9bb68e477e9510b70a6acf to your computer and use it in GitHub Desktop.
Parallel networking calls in Dart 2
@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