withTimeout<T> static method
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;
}
}