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

RetryResilienceStrategy<T>

using Polly.Telemetry; using Polly.Utils; 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> : OutcomeResilienceStrategy<T> { private readonly TimeProvider _timeProvider; private readonly ResilienceStrategyTelemetry _telemetry; private readonly RandomUtil _randomUtil; 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; } [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, bool isGeneric, TimeProvider timeProvider, ResilienceStrategyTelemetry telemetry, RandomUtil randomUtil) : base(isGeneric) { ShouldHandle = options.ShouldHandle; BaseDelay = options.BaseDelay; BackoffType = options.BackoffType; RetryCount = options.RetryCount; OnRetry = options.OnRetry; DelayGenerator = options.RetryDelayGenerator; _timeProvider = timeProvider; _telemetry = telemetry; _randomUtil = randomUtil; } [AsyncStateMachine(typeof(<ExecuteCallbackAsync>d__22<>))] [return: System.Runtime.CompilerServices.Nullable(new byte[] { 0, 0, 1 })] protected override ValueTask<Outcome<T>> ExecuteCallbackAsync<[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) { <ExecuteCallbackAsync>d__22<TState> stateMachine = default(<ExecuteCallbackAsync>d__22<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) { if (RetryCount == -1) return false; return attempt >= RetryCount; } } }