Class HedgeOptions
- Namespace
- Kevlar
- Assembly
- Kevlar.dll
Configuration for a hedging strategy: launch up to MaxHedgedAttempts additional attempts, staggered by Delay, and return the first acceptable outcome. A handled failure always launches the next attempt immediately.
public sealed class HedgeOptions
- Inheritance
-
HedgeOptions
- Inherited Members
Remarks
The executed delegate may be invoked multiple times concurrently — it must be safe to do so. Hedging requires asynchronous execution. If no attempt produces an acceptable outcome, the final outcome processed by the coordinator surfaces; selection among attempts already completed is not chronological. Before an additional attempt starts, callbacks run in this order: DelayGenerator, OnHedge, then ActionGenerator. Caller cancellation is checked before callbacks and again before the generated operation starts.
Constructors
HedgeOptions()
public HedgeOptions()
Properties
ActionGenerator
Selects a replacement operation for each additional attempt. A null result runs the original operation.
public Func<HedgeActionGeneratorEvent, Func<CancellationToken, ValueTask>?>? ActionGenerator { get; set; }
Property Value
Delay
Time to wait before launching the next attempt while the current ones are still running. Zero removes timer staggering and starts scheduling the original and all additional attempts, even when the original completes synchronously. Callbacks and cancellation checks can still delay or prevent an additional delegate from starting. Any negative value hedges only on failure and is normalized to InfiniteTimeSpan. Default 1 second.
public TimeSpan Delay { get; set; }
Property Value
DelayGenerator
Selects the delay before each additional attempt while earlier attempts remain pending,
and is awaited before the attempt is scheduled. The generated value replaces
Delay for that attempt. Negative values are treated as
Zero and values above the runtime timer limit are clamped. Return
new(delay) from a synchronous generator.
public Func<HedgeDelayEvent, ValueTask<TimeSpan>>? DelayGenerator { get; set; }
Property Value
HandlesException
Setting this — or, on HedgeOptions<TResult>, its HandlesResult — makes
this hedging strategy ignore the ambient When… handling clause; this predicate then
selects the exceptions it handles.
public Func<Exception, bool>? HandlesException { get; set; }
Property Value
Remarks
The ambient clause is started with When… on a shield and continued with Or… on
the builder it returns, and applies to every reactive strategy chained after it. These
properties replace that clause for this strategy alone; they do not narrow it.
- See Also
HandlesExceptionContext
Locally handles exceptions using execution context and attempt metadata.
public Func<HandlingEvent, bool>? HandlesExceptionContext { get; set; }
Property Value
MaxHedgedAttempts
Maximum additional attempts after the original. Default 1.
public int MaxHedgedAttempts { get; set; }
Property Value
Name
An optional low-cardinality name used by strategy telemetry.
public string? Name { get; set; }
Property Value
OnHedge
Invoked and awaited before an additional hedged attempt starts. Return default from a synchronous callback.
public Func<HedgeEvent, ValueTask>? OnHedge { get; set; }