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

MonkeyStrategy

Contains common functionality for chaos strategies which intentionally disrupt executions - which monkey around with calls.
using Polly.Utils; using System; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Polly.Simmy { internal abstract class MonkeyStrategy : ResilienceStrategy { [System.Runtime.CompilerServices.Nullable(1)] 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; } [System.Runtime.CompilerServices.NullableContext(1)] protected MonkeyStrategy(MonkeyStrategyOptions options) { Guard.NotNull(options, "options"); Guard.NotNull(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)))); } [AsyncStateMachine(typeof(<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; } } }