withTimeout method

Future<T> withTimeout(
  1. Duration timeout, {
  2. T? fallback,
})

超时处理

Implementation

Future<T> withTimeout(Duration timeout, {T? fallback}) {
  return this.timeout(
    timeout,
    onTimeout: () {
      if (fallback != null) return fallback;
      throw TimeoutException('Future did not complete in $timeout');
    },
  );
}