diff --git a/src/Polly.Core/Hedging/Controller/HedgingExecutionContext.cs b/src/Polly.Core/Hedging/Controller/HedgingExecutionContext.cs index 2a2ed1454c..c55641783f 100644 --- a/src/Polly.Core/Hedging/Controller/HedgingExecutionContext.cs +++ b/src/Polly.Core/Hedging/Controller/HedgingExecutionContext.cs @@ -202,21 +202,9 @@ private void UpdateOriginalContext() return; } - int accepted = 0; - TaskExecution? acceptedExecution = null; + Debug.Assert(Tasks.Count(t => t.IsAccepted) == 1, $"There must be exactly one accepted outcome for hedging. Found {Tasks.Count(t => t.IsAccepted)}."); - foreach (var task in Tasks) - { - if (task.IsAccepted) - { - accepted++; - acceptedExecution = task; - } - } - - Debug.Assert(accepted == 1, $"There must be exactly one accepted outcome for hedging. Found {accepted}."); - - if (acceptedExecution is not null) + if (Tasks.FirstOrDefault(static t => t.IsAccepted) is TaskExecution acceptedExecution) { originalContext.Properties.Replace(acceptedExecution.Properties);