From fbe09a60b2d0786c8194484666b746b32d34b0f9 Mon Sep 17 00:00:00 2001 From: SebastienDegodez Date: Sat, 21 Dec 2024 23:51:46 +0100 Subject: [PATCH] refactor: adjust cancellation token handling in WaitForConditionAsync Signed-off-by: SebastienDegodez --- .../MicrocksContainerExtensions.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microcks.Testcontainers/MicrocksContainerExtensions.cs b/src/Microcks.Testcontainers/MicrocksContainerExtensions.cs index 0cff3e1..106ea31 100644 --- a/src/Microcks.Testcontainers/MicrocksContainerExtensions.cs +++ b/src/Microcks.Testcontainers/MicrocksContainerExtensions.cs @@ -100,12 +100,12 @@ private static async Task RefreshTestResultAsync(string httpEndpoint private static async Task WaitForConditionAsync(Func> 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()) { @@ -113,7 +113,7 @@ private static async Task WaitForConditionAsync(Func> condition, Time { throw new TaskCanceledException(); } - await Task.Delay(interval, cancellationTokenSource.Token); + await Task.Delay(interval, CancellationToken.None); } }