Skip to content

Commit 61dbb0b

Browse files
committed
Slightly more defensive pattern since we care about the completion source transitioning into the completed state regardless whether it comes from cancellation or signal
1 parent 60dc06e commit 61dbb0b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/NServiceBus.Transport.Sql.Shared/Receiving/AsyncCountdownLatch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public AsyncCountdownLatch(int count)
2222

2323
public async Task WaitAsync(CancellationToken cancellationToken = default)
2424
{
25-
var registration = cancellationToken.Register(static state => ((TaskCompletionSource)state).SetResult(), completionSource);
25+
var registration = cancellationToken.Register(static state => ((TaskCompletionSource)state).TrySetResult(), completionSource);
2626
await using var _ = registration.ConfigureAwait(false);
2727
await completionSource.Task.ConfigureAwait(false);
2828
}
@@ -33,7 +33,7 @@ void Signal()
3333
{
3434
if (Interlocked.Decrement(ref count) == 0)
3535
{
36-
completionSource.SetResult();
36+
_ = completionSource.TrySetResult();
3737
}
3838
}
3939

0 commit comments

Comments
 (0)