Skip to content

Instantly share code, notes, and snippets.

@givip
Last active September 15, 2023 09:33
Show Gist options
  • Save givip/e3f17555287450b558d4705f6b2ce999 to your computer and use it in GitHub Desktop.
Save givip/e3f17555287450b558d4705f6b2ce999 to your computer and use it in GitHub Desktop.
void main(List<String> arguments) async {
try {
final result = await getInt();
print(result);
} catch (e) {
print(2);
} finally {
print(3);
}
}
Future<int> getInt() async {
final result = await Future.delayed(
const Duration(seconds: 2),
() => 1,
).timeout(
const Duration(seconds: 1),
onTimeout: () => 5,
);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment