Skip to content

Instantly share code, notes, and snippets.

@VB10
Last active September 28, 2023 14:44
Show Gist options
  • Save VB10/e5b3c3b133360d21b88cd87c3e0f9589 to your computer and use it in GitHub Desktop.
Save VB10/e5b3c3b133360d21b88cd87c3e0f9589 to your computer and use it in GitHub Desktop.
Timeout
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