Class HedgingPolicy
- Namespace
- Excalibur.Dispatch.Resilience.Polly
- Assembly
- Excalibur.Dispatch.Resilience.Polly.dll
Hedging policy that sends parallel requests after a configured delay, returning the first successful result to reduce tail latency.
public sealed class HedgingPolicy
- Inheritance
-
HedgingPolicy
- Inherited Members
- Extension Methods
Remarks
Uses Polly v8's hedging strategy under the hood. Hedging is particularly useful for read operations or idempotent writes where latency reduction is more important than resource conservation.
Constructors
HedgingPolicy(HedgingOptions, ILogger<HedgingPolicy>?)
Initializes a new instance of the HedgingPolicy class.
public HedgingPolicy(HedgingOptions options, ILogger<HedgingPolicy>? logger = null)
Parameters
optionsHedgingOptionsThe hedging options.
loggerILogger<HedgingPolicy>Optional logger instance.
Methods
ExecuteAsync(Func<CancellationToken, Task>, CancellationToken)
Executes a void operation with hedging protection.
public Task ExecuteAsync(Func<CancellationToken, Task> operation, CancellationToken cancellationToken)
Parameters
operationFunc<CancellationToken, Task>The operation to execute.
cancellationTokenCancellationTokenThe cancellation token to observe.
Returns
- Task
A task representing the asynchronous operation.
ExecuteAsync<TResult>(Func<CancellationToken, Task<TResult>>, CancellationToken)
Executes an operation with hedging protection.
public Task<TResult> ExecuteAsync<TResult>(Func<CancellationToken, Task<TResult>> operation, CancellationToken cancellationToken) where TResult : class
Parameters
operationFunc<CancellationToken, Task<TResult>>The operation to execute.
cancellationTokenCancellationTokenThe cancellation token to observe.
Returns
- Task<TResult>
The result from the first successful attempt.
Type Parameters
TResultThe type of result returned by the operation.