Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Polly-Contrib/Simmy/llms.txt
Use this file to discover all available pages before exploring further.
InjectLatencyOptions and InjectLatencyAsyncOptions are the configuration objects you supply to MonkeyPolicy.InjectLatency and MonkeyPolicy.InjectLatencyAsync. Both types use a fluent builder pattern: a configuration callback receives a fresh options instance, you chain .Latency(...), .InjectionRate(...), and .Enabled(...) calls, and the factory validates the result before constructing the policy. Latency is always injected before the wrapped delegate executes — the policy sleeps first, then runs your code. This makes it easy to simulate downstream slowness without modifying the application under test.
Namespaces
InjectLatencyOptions (sync)
InjectionRate and Enabled delegates from InjectOptionsBase. The internal LatencyInternal property holds the TimeSpan delegate and is set by the .Latency(...) extension methods below.
InjectLatencyAsyncOptions (async)
InjectionRate and Enabled delegates from InjectOptionsAsyncBase. The internal LatencyInternal property is Func<Context, CancellationToken, Task<TimeSpan>>.
Latency extension methods
.Latency(TimeSpan) — sync, fixed duration
Configures a constant delay to inject before the wrapped delegate.
The sync options object being configured (supplied automatically by the fluent chain).
The fixed duration to sleep before executing the wrapped call. For example,
TimeSpan.FromSeconds(5) simulates a five-second downstream stall..Latency(Func<Context, CancellationToken, TimeSpan>) — sync delegate
Configures a delegate that is evaluated at injection-time to produce the delay. Use this when the latency amount must vary per call — for example, based on the operation key stored in the Polly Context.
The sync options object being configured.
A synchronous delegate invoked at injection-time. Receives the current Polly
Context and a CancellationToken; returns the TimeSpan delay to apply for this execution..Latency(TimeSpan) — async, fixed duration
Configures a fixed delay for an async latency policy. The value is wrapped in Task.FromResult internally.
The async options object being configured.
The fixed duration to inject. Uses
Task.Delay internally so it does not block the thread..Latency(Func<Context, CancellationToken, Task<TimeSpan>>) — async delegate
Configures an async delegate that resolves the delay at injection-time, enabling dynamic latency values fetched from remote configuration.
The async options object being configured.
An async delegate returning
Task<TimeSpan>. Receives the Polly Context and CancellationToken; useful when the delay should be looked up from a live configuration or feature-flag service at the moment of injection.Inherited base options
InjectLatencyOptions inherits from InjectOptionsBase and InjectLatencyAsyncOptions from InjectOptionsAsyncBase. The following methods control when and how often chaos is triggered. All three must be configured — the factory throws ArgumentNullException for InjectionRate or Enabled if either is missing.
Sync base (InjectOptionsBaseExtensions)
.Enabled() — always on
.Enabled(true).
.Enabled(bool)
true to enable chaos injection; false to disable it entirely for all calls regardless of injection rate..EnabledWhen(Func<Context, CancellationToken, bool>)
A synchronous delegate evaluated on every execution. Return
true to permit injection for that call; false to skip it. Common use: gate chaos on an environment variable or per-operation-key flag..InjectionRate(double)
A constant value in
[0, 1]. 0.0 means the delay is never injected; 1.0 means every call is delayed. Values outside this range throw ArgumentOutOfRangeException..InjectionRate(Func<Context, CancellationToken, double>)
A delegate evaluated on each execution to provide a dynamic injection rate. Use this to ramp chaos up or down in production without redeploying.
Async base (InjectOptionsAsyncBaseExtensions)
The async base exposes the same .Enabled(), .Enabled(bool), and .InjectionRate(double) overloads and adds async-delegate variants:
.EnabledWhen(Func<Context, CancellationToken, Task<bool>>)
An async delegate returning
Task<bool>. Use this when the enabled check must call an async service, such as a remote feature-flag API..InjectionRate(Func<Context, CancellationToken, Task<double>>)
An async delegate returning
Task<double> in [0, 1]. Enables the chaos rate to be fetched from an async configuration service on every execution.