RetryResilienceStrategy<T>
using Polly.Telemetry;
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace Polly.Retry
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})]
internal sealed class RetryResilienceStrategy<[System.Runtime.CompilerServices.Nullable(2)] T> : ReactiveResilienceStrategy<T>
{
private readonly TimeProvider _timeProvider;
private readonly ResilienceStrategyTelemetry _telemetry;
private readonly Func<double> _randomizer;
public TimeSpan BaseDelay { get; }
public RetryBackoffType BackoffType { get; }
public int RetryCount { get; }
[System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
0
})]
[field: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
0
})]
public Func<OutcomeArguments<T, RetryPredicateArguments>, ValueTask<bool>> ShouldHandle {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
0
})]
get;
}
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
0
})]
[field: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
0
})]
public Func<OutcomeArguments<T, RetryDelayArguments>, ValueTask<TimeSpan>> DelayGenerator {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
0
})]
get;
}
public bool UseJitter { get; }
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
1
})]
[field: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
1
})]
public Func<OutcomeArguments<T, OnRetryArguments>, ValueTask> OnRetry {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
1
})]
get;
}
public RetryResilienceStrategy(RetryStrategyOptions<T> options, TimeProvider timeProvider, ResilienceStrategyTelemetry telemetry, Func<double> randomizer)
{
ShouldHandle = options.ShouldHandle;
BaseDelay = options.BaseDelay;
BackoffType = options.BackoffType;
RetryCount = options.RetryCount;
OnRetry = options.OnRetry;
DelayGenerator = options.RetryDelayGenerator;
UseJitter = options.UseJitter;
_timeProvider = timeProvider;
_telemetry = telemetry;
_randomizer = randomizer;
}
[AsyncStateMachine(typeof(<ExecuteCore>d__25<>))]
[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__25<TState> stateMachine = default(<ExecuteCore>d__25<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;
}
private bool IsLastAttempt(int attempt)
{
return attempt >= RetryCount;
}
}
}