withTimeout<T> static method

Future<T> withTimeout<T>(
  1. Future<T> operation(), {
  2. Duration timeout = const Duration(seconds: 30),
  3. int? streamId,
  4. String? operationName,
  5. String? currentState,
})

Executes an operation with a timeout and proper Yamux exception handling

Implementation

static Future<T> withTimeout<T>(
  Future<T> Function() operation, {
  Duration timeout = const Duration(seconds: 30),
  int? streamId,
  String? operationName,
  String? currentState,
}) async {
  try {
    return await operation().timeout(timeout);
  } on TimeoutException catch (e, stackTrace) {
    throw YamuxExceptionHandler.classifyYamuxException(
      e,
      stackTrace,
      streamId: streamId,
      operation: operationName,
      currentState: currentState,
    );
  } catch (e, stackTrace) {
    if (e is Exception) {
      throw YamuxExceptionHandler.classifyYamuxException(
        e,
        stackTrace,
        streamId: streamId,
        operation: operationName,
        currentState: currentState,
      );
    }
    rethrow;
  }
}