Skip to content

Instantly share code, notes, and snippets.

@ProZhar
Forked from eduardoflorence/main.dart
Created February 18, 2023 13:15
Show Gist options
  • Save ProZhar/add0ba4b1ec8f3332e7611356b21ea49 to your computer and use it in GitHub Desktop.
Save ProZhar/add0ba4b1ec8f3332e7611356b21ea49 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