Created
October 5, 2020 22:02
-
-
Save eduardoflorence/15c9ed5550ad2d3cf6963641bfd20410 to your computer and use it in GitHub Desktop.
Dart Future - Testes de timeout
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
// 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