Skip to content

Forma correta de trabalhar com vários Future async await #17

Discussion options

You must be logged in to vote

Você pode usar Future.wait e colocar todas as variáveis tipo Future ali. Ao invés de executar um por um ele irá executar todos em paralelo finalizando apenas quando o Future mais demorado terminar a execução

Ex:

 final ClienteProdutoStore clienteProdutoStore = Modular.get();
  final ClienteLinhaProdutoStore clienteLinhaProdutoStore =Modular.get();
  final ClienteGrupoProdutoStore clienteGrupoProdutoStore =  Modular.get();

Future.wait([clienteProdutoStore, clienteLinhaProdutoStore, clienteGrupoProdutoStore]);

Observe que retirei os "await" da frente do Modular.get para ele me retornar o Future do método a ser executado posteriormente

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
2 replies
@seadramdesenv
Comment options

@DouglasValerio
Comment options

Comment options

You must be logged in to vote
6 replies
@jacobaraujo7
Comment options

@Anzell
Comment options

@seadramdesenv
Comment options

@seadramdesenv
Comment options

@seadramdesenv
Comment options

Answer selected by Bwolfs2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants