Skip to content

Commit 24fa327

Browse files
committed
* Consistently use TryRemove
1 parent 13de610 commit 24fa327

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ private void HandleAck(ulong deliveryTag, bool multiple)
184184
{
185185
if (pair.Key <= deliveryTag)
186186
{
187-
pair.Value.SetResult(true);
188-
_confirmsTaskCompletionSources.Remove(pair.Key, out _);
187+
if (_confirmsTaskCompletionSources.TryRemove(pair.Key, out TaskCompletionSource<bool>? tcs))
188+
{
189+
tcs.SetResult(true);
190+
}
189191
}
190192
}
191193
}
@@ -210,14 +212,16 @@ private void HandleNack(ulong deliveryTag, bool multiple, bool isReturn)
210212
{
211213
if (pair.Key <= deliveryTag)
212214
{
213-
pair.Value.SetException(new PublishException(pair.Key, isReturn));
214-
_confirmsTaskCompletionSources.Remove(pair.Key, out _);
215+
if (_confirmsTaskCompletionSources.TryRemove(pair.Key, out TaskCompletionSource<bool>? tcs))
216+
{
217+
tcs.SetException(new PublishException(pair.Key, isReturn));
218+
}
215219
}
216220
}
217221
}
218222
else
219223
{
220-
if (_confirmsTaskCompletionSources.Remove(deliveryTag, out TaskCompletionSource<bool>? tcs))
224+
if (_confirmsTaskCompletionSources.TryRemove(deliveryTag, out TaskCompletionSource<bool>? tcs))
221225
{
222226
tcs.SetException(new PublishException(deliveryTag, isReturn));
223227
}
@@ -382,7 +386,7 @@ await publisherConfirmationInfo.MaybeWaitForConfirmationAsync(cancellationToken)
382386
}
383387
catch (OperationCanceledException)
384388
{
385-
_confirmsTaskCompletionSources.Remove(publisherConfirmationInfo.PublishSequenceNumber, out _);
389+
_confirmsTaskCompletionSources.TryRemove(publisherConfirmationInfo.PublishSequenceNumber, out _);
386390
throw;
387391
}
388392
finally

0 commit comments

Comments
 (0)