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

TimeoutResilienceStrategyBuilderExtensions

Extension methods for adding timeouts to a ResilienceStrategyBuilder.
using Polly.Timeout; using Polly.Utils; using System; using System.Runtime.CompilerServices; namespace Polly { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public static class TimeoutResilienceStrategyBuilderExtensions { public static TBuilder AddTimeout<[System.Runtime.CompilerServices.Nullable(0)] TBuilder>(this TBuilder builder, TimeSpan timeout) where TBuilder : ResilienceStrategyBuilderBase { Guard.NotNull(builder, "builder"); return builder.AddTimeout(new TimeoutStrategyOptions { Timeout = timeout }); } public static TBuilder AddTimeout<[System.Runtime.CompilerServices.Nullable(0)] TBuilder>(this TBuilder builder, TimeoutStrategyOptions options) where TBuilder : ResilienceStrategyBuilderBase { Guard.NotNull(builder, "builder"); Guard.NotNull(options, "options"); builder.AddStrategy((ResilienceStrategyBuilderContext context) => new TimeoutResilienceStrategy(options, context.TimeProvider, context.Telemetry), options); return builder; } } }