<PackageReference Include="Polly.Core" Version="8.0.0-beta.2" />

HedgingResilienceStrategy<T>

using Polly.Hedging.Utils; using Polly.Telemetry; using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Polly.Hedging { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] internal sealed class HedgingResilienceStrategy<[System.Runtime.CompilerServices.Nullable(2)] T> : ResilienceStrategy<T> { private readonly TimeProvider _timeProvider; private readonly ResilienceStrategyTelemetry _telemetry; private readonly HedgingController<T> _controller; public TimeSpan HedgingDelay { get; } public int TotalAttempts { get; } [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0 })] [field: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0 })] public Func<HedgingDelayGeneratorArguments, ValueTask<TimeSpan>> DelayGenerator { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0 })] get; } public HedgingHandler<T> HedgingHandler { get; } [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1 })] [field: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1 })] public Func<OnHedgingArguments<T>, ValueTask> OnHedging { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1 })] get; } public HedgingResilienceStrategy(TimeSpan hedgingDelay, int maxHedgedAttempts, HedgingHandler<T> hedgingHandler, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0, 1 })] Func<OnHedgingArguments<T>, ValueTask> onHedging, [System.Runtime.CompilerServices.Nullable(new byte[] { 2, 0 })] Func<HedgingDelayGeneratorArguments, ValueTask<TimeSpan>> hedgingDelayGenerator, TimeProvider timeProvider, ResilienceStrategyTelemetry telemetry) { HedgingDelay = hedgingDelay; TotalAttempts = maxHedgedAttempts + 1; DelayGenerator = hedgingDelayGenerator; _timeProvider = timeProvider; HedgingHandler = hedgingHandler; OnHedging = onHedging; _telemetry = telemetry; _controller = new HedgingController<T>(telemetry, timeProvider, HedgingHandler, TotalAttempts); } [AsyncStateMachine(typeof(<ExecuteCore>d__19<>))] [ExcludeFromCodeCoverage] [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 0, 1 })] protected internal override ValueTask<Outcome<T>> ExecuteCore<[System.Runtime.CompilerServices.Nullable(2)] TState>([System.Runtime.CompilerServices.Nullable(new byte[] { 1, 1, 1, 0, 0, 1 })] Func<ResilienceContext, TState, ValueTask<Outcome<T>>> callback, ResilienceContext context, TState state) { <ExecuteCore>d__19<TState> stateMachine = default(<ExecuteCore>d__19<TState>); stateMachine.<>t__builder = AsyncValueTaskMethodBuilder<Outcome<T>>.Create(); stateMachine.<>4__this = this; stateMachine.callback = callback; stateMachine.context = context; stateMachine.state = state; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<ExecuteCoreAsync>d__20<>))] [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 0, 1 })] private ValueTask<Outcome<T>> ExecuteCoreAsync<[System.Runtime.CompilerServices.Nullable(2)] TState>(HedgingExecutionContext<T> hedgingContext, [System.Runtime.CompilerServices.Nullable(new byte[] { 1, 1, 1, 0, 0, 1 })] Func<ResilienceContext, TState, ValueTask<Outcome<T>>> callback, ResilienceContext context, TState state) { <ExecuteCoreAsync>d__20<TState> stateMachine = default(<ExecuteCoreAsync>d__20<TState>); stateMachine.<>t__builder = AsyncValueTaskMethodBuilder<Outcome<T>>.Create(); stateMachine.<>4__this = this; stateMachine.hedgingContext = hedgingContext; stateMachine.callback = callback; stateMachine.context = context; stateMachine.state = state; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(HedgingResilienceStrategy<>.<HandleOnHedgingAsync>d__21))] private ValueTask HandleOnHedgingAsync([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] OnHedgingArguments<T> args) { <HandleOnHedgingAsync>d__21 stateMachine = default(<HandleOnHedgingAsync>d__21); stateMachine.<>t__builder = AsyncValueTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.args = args; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start<<HandleOnHedgingAsync>d__21>(ref stateMachine); return stateMachine.<>t__builder.Task; } [System.Runtime.CompilerServices.NullableContext(0)] internal ValueTask<TimeSpan> GetHedgingDelayAsync([System.Runtime.CompilerServices.Nullable(1)] ResilienceContext context, int attempt) { if (DelayGenerator == null) return new ValueTask<TimeSpan>(HedgingDelay); return DelayGenerator(new HedgingDelayGeneratorArguments(context, attempt)); } } }