Simmy ships async variants of every chaos policy. The async forms integrate naturally withDocumentation 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.
async/await application code, support cooperative cancellation throughout, and return awaitable policy instances that slot into Polly’s PolicyWrap alongside other async resilience policies. The factory API mirrors the synchronous one exactly — you use the same fluent builder options — but the underlying delegates return Task<T> rather than T, and cancellation tokens are propagated through every layer.
Factory Methods
All async monkey policies are created through static methods onMonkeyPolicy. Each method accepts a configuration callback that receives a typed async-options object.
Exactly three options are required on every async policy: the chaos payload (e.g.
Fault, Latency, Behaviour, Result), InjectionRate, and Enabled (or EnabledWhen). Omitting any of them causes the factory method to throw ArgumentNullException.How Async Delegates Differ from Sync
The core difference between the sync and async options types is that allFunc<> delegates on the async variants return Task<T> instead of T. This means:
- The enabled check is
Func<Context, CancellationToken, Task<bool>>instead ofFunc<Context, CancellationToken, bool>. - The injection-rate provider is
Func<Context, CancellationToken, Task<double>>instead ofFunc<Context, CancellationToken, double>. - Outcome, latency, and behaviour delegates all return awaitables.
- Sync EnabledWhen
- Async EnabledWhen
- Sync InjectionRate
- Async InjectionRate
InjectExceptionAsync
Throws a configured exception before the wrapped call executes. Useful for simulating downstream service failures in async call chains.Func<Context, CancellationToken, Task<Exception>>:
InjectResultAsync
Substitutes a fake result without executing the inner call. Ideal for simulating error responses from HTTP APIs or databases in async pipelines.Func<Context, CancellationToken, Task<TResult>>:
InjectLatencyAsync
Delays execution by the configuredTimeSpan before the wrapped call runs. Since v0.2.0, the injected delay is cancellable: if the CancellationToken is signalled during the delay, the delay ends and the cancellation propagates normally.
Because latency injection uses
Task.Delay internally, the injected pause participates in cooperative cancellation. A timeout policy wrapping the chaos policy will cancel the delay exactly as it would cancel a real slow downstream call.InjectBehaviourAsync
Executes aFunc<Task> (or Func<Context, CancellationToken, Task>) before the wrapped call. Use this to simulate side effects such as cache eviction, VM restarts, or sending notifications.
Executing Async Policies
CallExecuteAsync to run code through an async monkey policy, passing a cancellation token:
CancellationToken is forwarded to:
- The
EnabledWhendelegate - The
InjectionRatedelegate - The chaos payload delegate (fault factory, latency factory, behaviour)
- The user-supplied inner delegate
Complete Async PolicyWrap Example
The recommended way to use async Simmy policies in production is inside an asyncPolicyWrap, with the chaos policy as the innermost policy. For a detailed explanation of why placement matters, see Policy Wrap.