withTimeout<T2> method
Future<T2>
withTimeout<T2>(
- Duration timeout,
- FutureSuspendBlock<
T2> block, { - int? debugCallStackLevel,
タイムアウト付きの非同期処理を開始する.
タイムアウトが発生した場合、 block()は TimeoutException が発生して終了する.
Implementation
Future<T2> withTimeout<T2>(
Duration timeout,
FutureSuspendBlock<T2> block, {
int? debugCallStackLevel,
}) async {
final child = FutureContext.child(
this,
debugCallStackLevel: debugCallStackLevel ?? 1,
);
try {
return await child.suspend(block).timeout(timeout);
} on TimeoutException catch (e) {
throw TimeoutException('${e.message}, timeout: $timeout');
} finally {
await child.close();
}
}