Class RetryOptions<TResult>
- Namespace
- Kevlar
- Assembly
- Kevlar.dll
Result-typed configuration for a retry strategy on a Shield<TResult>: the events carry a typed Outcome<T> instead of a boxed object result.
public sealed class RetryOptions<TResult>
Type Parameters
TResult
- Inheritance
-
RetryOptions<TResult>
- Inherited Members
Remarks
RetryOptions<TResult> and RetryOptions are standalone sibling types. Their callback properties expose distinct delegate types and preserve the delegates assigned to them. 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. 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, with the typed handled outcome. Return a non-null value to replace the backoff-computed delay; MaxDelay still caps the returned value. When it is unset, MaxDelay caps the value when available. The generator is awaited before OnRetry runs.
public Func<RetryEvent<TResult>, ValueTask<TimeSpan?>>? DelayGenerator { get; set; }
Property Value
- Func<RetryEvent<TResult>, ValueTask<TimeSpan?>>
HandlesException
Setting this — or HandlesResult — makes this retry 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 retry 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>
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, with the typed handled outcome. Return default from a synchronous callback.
public Func<RetryEvent<TResult>, ValueTask>? OnRetry { get; set; }
Property Value
- Func<RetryEvent<TResult>, ValueTask>