Table of Contents

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

options HedgingOptions

The hedging options.

logger ILogger<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

operation Func<CancellationToken, Task>

The operation to execute.

cancellationToken CancellationToken

The 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

operation Func<CancellationToken, Task<TResult>>

The operation to execute.

cancellationToken CancellationToken

The cancellation token to observe.

Returns

Task<TResult>

The result from the first successful attempt.

Type Parameters

TResult

The type of result returned by the operation.