Class RetryOptions
- Namespace
- Kevlar
- Assembly
- Kevlar.dll
Configuration for a retry strategy.
public sealed class RetryOptions
- Inheritance
-
RetryOptions
- Inherited Members
Remarks
Before each retry, DelayGenerator runs and is awaited, then OnRetry.
If the caller's cancellation token is cancelled by the time the callbacks complete, the retry
stops and surfaces caller cancellation. Hooks that complete synchronously (for example by
returning default) add no overhead and remain compatible with synchronous
Execute.
Cancellation during the retry delay surfaces an OperationCanceledException with
no inner exception. The handled outcome is no longer retained, and OnRetry has
already run for the suppressed attempt.
Constructors
RetryOptions()
public RetryOptions()
Properties
Backoff
The delay computation between attempts. Defaults to Default.
public Backoff Backoff { get; set; }
Property Value
DelayGenerator
Overrides the computed delay for a specific retry. Receives the event with the
backoff-computed delay; return a non-null value to replace it (for example, from an
HTTP Retry-After header). MaxDelay still caps the returned value.
When it is unset, MaxDelay caps the value when available.
The generator is awaited before OnRetry runs. Do not retain the pooled
Context after the returned task completes.
public Func<RetryEvent, ValueTask<TimeSpan?>>? DelayGenerator { get; set; }
Property Value
HandlesException
Setting this makes this retry ignore the ambient When… handling clause and handle
only the exceptions this predicate selects.
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. This
property replaces that clause for this strategy alone; it does not narrow it.
- See Also
HandlesExceptionContext
Locally handles exceptions using execution context and attempt metadata.
public Func<HandlingEvent, bool>? HandlesExceptionContext { get; set; }
Property Value
MaxDelay
An absolute upper bound applied to every delay, including delays produced by
DelayGenerator (so a huge Retry-After header cannot stall the pipeline).
When unset, MaxDelay is used when the backoff provides one.
public TimeSpan? MaxDelay { get; set; }
Property Value
MaxRetries
The number of retries made after the initial attempt — not the number of attempts.
MaxRetries = 3 (the default) makes up to 4 total attempts: the initial call plus
3 retries. Use MaxValue to retry forever.
public int MaxRetries { get; set; }
Property Value
Name
An optional low-cardinality name used by strategy telemetry.
public string? Name { get; set; }
Property Value
OnRetry
Invoked and awaited before each retry sleeps. Return default from a synchronous callback. Do not retain the pooled Context after the returned task completes.
public Func<RetryEvent, ValueTask>? OnRetry { get; set; }