namespace qdr.fnd.core.pqueue.fnd.candidates { internal static class TaskExt { public static async Task TimeoutAfter(this Task task,CancellationTokenSource timeoutCancellationTokenSource, TimeSpan timeout) { if (await Task.WhenAny(task, Task.Delay(timeout, timeoutCancellationTokenSource.Token)) == task) { timeoutCancellationTokenSource.Cancel(); await task; return; } throw new TimeoutException("The operation has timed out."); } } }