Skip to content

Commit

Permalink
refactor: adjust cancellation token handling in WaitForConditionAsync
Browse files Browse the repository at this point in the history
Signed-off-by: SebastienDegodez <[email protected]>
  • Loading branch information
SebastienDegodez committed Dec 22, 2024
1 parent a55a953 commit fbe09a6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Microcks.Testcontainers/MicrocksContainerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ private static async Task<TestResult> RefreshTestResultAsync(string httpEndpoint

private static async Task WaitForConditionAsync(Func<Task<bool>> condition, TimeSpan atMost, TimeSpan delay, TimeSpan interval)
{
// Delay before first check
await Task.Delay(delay);

// Cancel after atMost
using var cancellationTokenSource = new CancellationTokenSource(atMost);

// Delay before first check
await Task.Delay(delay, cancellationTokenSource.Token);

// Polling
while (!await condition())
{
if (cancellationTokenSource.Token.IsCancellationRequested)
{
throw new TaskCanceledException();
}
await Task.Delay(interval, cancellationTokenSource.Token);
await Task.Delay(interval, CancellationToken.None);
}
}

Expand Down

0 comments on commit fbe09a6

Please sign in to comment.