<PackageReference Include="Polly.Core" Version="8.2.1" />

TimeoutResilienceStrategy

using Polly.Telemetry; using Polly.Utils; using System; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace Polly.Timeout { [NullableContext(1)] [Nullable(0)] internal sealed class TimeoutResilienceStrategy : ResilienceStrategy { private readonly ResilienceStrategyTelemetry _telemetry; private readonly CancellationTokenSourcePool _cancellationTokenSourcePool; public TimeSpan DefaultTimeout { get; } [Nullable(new byte[] { 2, 0 })] [field: Nullable(new byte[] { 2, 0 })] public Func<TimeoutGeneratorArguments, ValueTask<TimeSpan>> TimeoutGenerator { [return: Nullable(new byte[] { 2, 0 })] get; } [Nullable(2)] [field: Nullable(2)] public Func<OnTimeoutArguments, ValueTask> OnTimeout { [NullableContext(2)] get; } public TimeoutResilienceStrategy(TimeoutStrategyOptions options, TimeProvider timeProvider, ResilienceStrategyTelemetry telemetry) { DefaultTimeout = options.Timeout; TimeoutGenerator = options.TimeoutGenerator; OnTimeout = options.OnTimeout; _telemetry = telemetry; _cancellationTokenSourcePool = CancellationTokenSourcePool.Create(timeProvider); } [AsyncStateMachine(typeof(<ExecuteCore>d__12<, >))] [return: Nullable(new byte[] { 0, 0, 1 })] protected internal override ValueTask<Outcome<TResult>> ExecuteCore<[Nullable(2)] TResult, [Nullable(2)] TState>([Nullable(new byte[] { 1, 1, 1, 0, 0, 1 })] Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, ResilienceContext context, TState state) { <ExecuteCore>d__12<TResult, TState> stateMachine = default(<ExecuteCore>d__12<TResult, TState>); stateMachine.<>t__builder = AsyncValueTaskMethodBuilder<Outcome<TResult>>.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 static CancellationTokenRegistration CreateRegistration(CancellationTokenSource cancellationSource, CancellationToken previousToken) { if (previousToken.CanBeCanceled) return previousToken.Register(delegate(object state) { ((CancellationTokenSource)state).Cancel(); }, cancellationSource, false); return default(CancellationTokenRegistration); } } }