Class HedgingStrategyOptions<TResult>
Hedging strategy options.
public class HedgingStrategyOptions<TResult> : ResilienceStrategyOptions
Type Parameters
TResult
The type of result these hedging options handle.
- Inheritance
-
HedgingStrategyOptions<TResult>
- Inherited Members
Constructors
HedgingStrategyOptions()
Initializes a new instance of the HedgingStrategyOptions<TResult> class.
public HedgingStrategyOptions()
Properties
ActionGenerator
Gets or sets a generator that creates hedged actions.
[Required]
public Func<HedgingActionGeneratorArguments<TResult>, Func<ValueTask<Outcome<TResult>>>?> ActionGenerator { get; set; }
Property Value
- Func<HedgingActionGeneratorArguments<TResult>, Func<ValueTask<Outcome<TResult>>>>
The default generator executes the original callback that was passed to the hedging resilience strategy. This property is required.
Delay
Gets or sets the maximum waiting time before spawning a new hedged action.
public TimeSpan Delay { get; set; }
Property Value
- TimeSpan
The default value is 2 seconds.
Remarks
You can use Zero to create all hedged actions (value of MaxHedgedAttempts) at once or InfiniteTimeSpan to force the hedging strategy to never create new action before the old one is finished.
If you want a greater control over hedging delay customization use DelayGenerator.
DelayGenerator
Gets or sets a generator that generates hedging delays for each hedging action.
public Func<HedgingDelayGeneratorArguments, ValueTask<TimeSpan>>? DelayGenerator { get; set; }
Property Value
- Func<HedgingDelayGeneratorArguments, ValueTask<TimeSpan>>
The default value is null.
Remarks
The DelayGenerator takes precedence over Delay. If specified, the Delay is ignored.
MaxHedgedAttempts
Gets or sets the maximum number of hedged actions to use, in addition to the original action.
[Range(1, 10)]
public int MaxHedgedAttempts { get; set; }
Property Value
- int
The default value is 1. The value must be bigger or equal to 1, and lower or equal to 10.
OnHedging
Gets or sets the event that is raised when a hedging is performed.
public Func<OnHedgingArguments<TResult>, ValueTask>? OnHedging { get; set; }
Property Value
- Func<OnHedgingArguments<TResult>, ValueTask>
The default value is null.
Remarks
The hedging is executed when the current attempt outcome is not successful and the ShouldHandle predicate returns true or when the current attempt did not finish within the Delay.
ShouldHandle
Gets or sets a predicate that determines whether the hedging should be executed for a given outcome.
[Required]
public Func<HedgingPredicateArguments<TResult>, ValueTask<bool>> ShouldHandle { get; set; }
Property Value
- Func<HedgingPredicateArguments<TResult>, ValueTask<bool>>
The default value is a predicate that hedges on any exception except OperationCanceledException. This property is required.