Skip to content

Instantly share code, notes, and snippets.

@eduardoflorence
Created October 5, 2020 22:02
Show Gist options
  • Save eduardoflorence/15c9ed5550ad2d3cf6963641bfd20410 to your computer and use it in GitHub Desktop.
Save eduardoflorence/15c9ed5550ad2d3cf6963641bfd20410 to your computer and use it in GitHub Desktop.
Dart Future - Testes de timeout
// Problema: then está sendo executado mesmo que timeout e catchError seja acionado
void main() {
final item = teste()
.then((value) => print('Executou then'))
.timeout(Duration(seconds: 2),
onTimeout: () {
throw ('Timeout expirado');
}
)
.catchError((e) => print('Erro $e'))
.whenComplete(() => print('Fim de tudo'));
}
Future teste() async {
await Future.delayed(Duration(seconds: 5));
return 42;
// return throw('ggghhh');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment