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 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; }
public HedgingResilienceStrategy(TimeSpan hedgingDelay, int maxHedgedAttempts, HedgingHandler<T> hedgingHandler, [System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0
})] Func<HedgingDelayGeneratorArguments, ValueTask<TimeSpan>> hedgingDelayGenerator, TimeProvider timeProvider, ResilienceStrategyTelemetry telemetry)
{
HedgingDelay = hedgingDelay;
TotalAttempts = maxHedgedAttempts + 1;
DelayGenerator = hedgingDelayGenerator;
HedgingHandler = hedgingHandler;
_controller = new HedgingController<T>(telemetry, timeProvider, HedgingHandler, TotalAttempts);
}
[AsyncStateMachine(typeof(<ExecuteCore>d__14<>))]
[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__14<TState> stateMachine = default(<ExecuteCore>d__14<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__15<>))]
[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__15<TState> stateMachine = default(<ExecuteCoreAsync>d__15<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;
}
[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));
}
}
}