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

ChaosStrategy<T>

public abstract class ChaosStrategy<T> : ResilienceStrategy<T>
Base class for generic (reactive) chaos strategies.
using Polly.Utils; using System; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Polly.Simmy { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] public abstract class ChaosStrategy<[System.Runtime.CompilerServices.Nullable(2)] T> : ResilienceStrategy<T> { private readonly Func<double> _randomizer; [System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] [field: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] internal Func<InjectionRateGeneratorArguments, ValueTask<double>> InjectionRateGenerator { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] get; } [System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] [field: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] internal Func<EnabledGeneratorArguments, ValueTask<bool>> EnabledGenerator { [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] get; } protected ChaosStrategy(ChaosStrategyOptions options) { Guard.NotNull<ChaosStrategyOptions>(options, "options"); Guard.NotNull<Func<double>>(options.Randomizer, "options.Randomizer"); _randomizer = options.Randomizer; InjectionRateGenerator = ((options.InjectionRateGenerator != null) ? options.InjectionRateGenerator : ((Func<InjectionRateGeneratorArguments, ValueTask<double>>)((InjectionRateGeneratorArguments _) => new ValueTask<double>(options.InjectionRate)))); EnabledGenerator = ((options.EnabledGenerator != null) ? options.EnabledGenerator : ((Func<EnabledGeneratorArguments, ValueTask<bool>>)((EnabledGeneratorArguments _) => new ValueTask<bool>(options.Enabled)))); } [System.Runtime.CompilerServices.NullableContext(0)] [AsyncStateMachine(typeof(ChaosStrategy<>.<ShouldInjectAsync>d__8))] protected ValueTask<bool> ShouldInjectAsync([System.Runtime.CompilerServices.Nullable(1)] ResilienceContext context) { <ShouldInjectAsync>d__8 stateMachine = default(<ShouldInjectAsync>d__8); stateMachine.<>t__builder = AsyncValueTaskMethodBuilder<bool>.Create(); stateMachine.<>4__this = this; stateMachine.context = context; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } } }