Class HedgeOptions<TResult>
- Namespace
- Kevlar
- Assembly
- Kevlar.dll
Result-typed configuration for a hedging strategy on a Shield<TResult>.
public sealed class HedgeOptions<TResult>
Type Parameters
TResult
- Inheritance
-
HedgeOptions<TResult>
- Inherited Members
Remarks
HedgeOptions<TResult> and HedgeOptions are standalone sibling types with matching shared property names and defaults. If no attempt produces an acceptable outcome, the final outcome processed by the coordinator surfaces; selection among attempts already completed is not chronological.
Constructors
HedgeOptions()
public HedgeOptions()
Properties
ActionGenerator
Selects a replacement operation for each additional attempt. A null result runs the original operation.
public Func<HedgeActionGeneratorEvent<TResult>, Func<CancellationToken, ValueTask<TResult>>?>? ActionGenerator { get; set; }
Property Value
- Func<HedgeActionGeneratorEvent<TResult>, Func<CancellationToken, ValueTask<TResult>>>
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 the typed outcome and execution context.
public Func<HandlingEvent<TResult>, bool>? HandlesExceptionContext { get; set; }
Property Value
- Func<HandlingEvent<TResult>, bool>
HandlesResult
Setting this — or HandlesException — makes this hedging strategy
ignore the ambient When… handling clause; this predicate then selects the results it
handles.
public Func<TResult, bool>? HandlesResult { get; set; }
Property Value
Remarks
The ambient clause is started with When…/WhenResult… 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
HandlesResultContext
Locally handles results using the typed outcome and execution context.
public Func<HandlingEvent<TResult>, bool>? HandlesResultContext { get; set; }
Property Value
- Func<HandlingEvent<TResult>, bool>
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, with the latest handled outcome when one triggered the hedge. Return default from a synchronous callback.
public Func<HedgeEvent<TResult>, ValueTask>? OnHedge { get; set; }
Property Value
- Func<HedgeEvent<TResult>, ValueTask>