RetryContext<T> Struct

Namespace
Kampute.Resilience
Assembly
  • Kampute.Resilience.dll

Definition

Describes a failed attempt of an operation that returns a value, and the delay before the operation is retried.
public readonly struct RetryContext<T>
Inheritance

Type Parameters

T
The type returned by the operation.

Remarks

RetryPolicy<T> passes this value to its delay override and retry handlers. An attempt fails either by throwing an exception that the policy retries or by returning a result that the policy retries; HasResult tells them apart.

Properties

AttemptNumber

Gets the number of the attempt that failed.
public uint AttemptNumber { get; }

Property Value

uint
A one-based number within this execution; the initial attempt is 1. It is also the number of retries made once this retry starts.

Delay

Gets the delay before the next attempt.
public TimeSpan Delay { get; }

Property Value

TimeSpan
In a delay override, the delay that the strategy proposes; in a retry handler, the delay that execution waits.

Elapsed

Gets the time since execution started when the outcome of the attempt was evaluated.
public TimeSpan Elapsed { get; }

Property Value

TimeSpan
The elapsed execution time, including earlier attempts and waits.

Exception

Gets the exception thrown by the attempt.
public Exception Exception { get; }

Property Value

Exception
The original exception, or null when the attempt returned a result.

HasResult

Gets whether the attempt returned a result rather than throwing an exception.
public bool HasResult { get; }

Property Value

bool
true for a returned result, including a null result; false for an exception.

Result

Gets the value returned by the attempt.
public T Result { get; }

Property Value

T
The returned value when HasResult is true; otherwise, the default value of T.

Operators

Implicit(RetryContext<T>)

Converts a context to the form that does not carry the result.
public static implicit operator RetryContext(RetryContext<T> context)

Parameters

context RetryContext<T>
The context to convert.

Returns

RetryContext
A RetryContext with the same attempt number, elapsed time, exception, and delay.