Last active
September 28, 2023 14:44
-
-
Save VB10/e5b3c3b133360d21b88cd87c3e0f9589 to your computer and use it in GitHub Desktop.
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
extension FutureExtension<T> on Future<T> { | |
Future<T?> timeoutOrNull({ | |
Duration timeOutDuration = const Duration(seconds: 10), | |
bool enableLogger = true, | |
}) async { | |
try { | |
final response = await timeout(timeOutDuration); | |
return response; | |
} catch (e) { | |
if (enableLogger) CustomLogger.log('$T $e'); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment