withTimeout method

Future<T> withTimeout([
  1. Duration duration = const Duration(seconds: 7)
])

Returns the original future but applies a timeout.

If the future does not complete within the given duration, a TimeoutException will be thrown.

The default duration is 7 seconds if not specified.

Example:

await someAsyncOperation().withTimeout(Duration(seconds: 5));

Implementation

Future<T> withTimeout([Duration duration = const Duration(seconds: 7)]) {
  return timeout(duration);
}