Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Sep 5, 2024
1 parent 9a0cb81 commit 986b97e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Serval/src/Serval.Shared/Utils/TaskEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ public static async Task Timeout(
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
Task task = action(cts.Token);
Task delayTask = Task.Delay(timeout, cancellationToken);
await Task.WhenAny(task, delayTask);
Task completedTask = await Task.WhenAny(task, delayTask);
if (delayTask.Status == TaskStatus.RanToCompletion)
{
if (throwOnTimeout)
throw new TimeoutException($"Operation timed out after {timeout}");
cts.Cancel();
}
await completedTask;
}
}

Expand Down

0 comments on commit 986b97e

Please sign in to comment.