Last active
November 8, 2024 08:58
-
-
Save givip/e3f17555287450b558d4705f6b2ce999 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
void main() 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), | |
() { | |
return 1; | |
}, | |
).timeout( | |
const Duration(seconds: 1), | |
onTimeout: () { | |
return 5; | |
}, | |
); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment