IRetrySession Interface

Namespace
Kampute.Resilience
Assembly
  • Kampute.Resilience.dll

Definition

Represents the retry state of one operation: it decides whether the operation is retried after a failure, and waits before the retry.
public interface IRetrySession
Implemented by

Remarks

A session is created for one operation and is used for all its failures, so that the retries it counts and the time it measures cover the whole operation. RetrySession applies an IRetryStrategy; other implementations can take the decision from elsewhere, such as the state of the application.

Sessions serve retry loops that you write yourself. RetryPolicy and the Execute methods of a strategy keep their own retry state and do not use a session. To base the delay on the failure, such as a retry time that it suggests, use RetryPolicy.OverrideDelay(Func<RetryContext, TimeSpan>).

Methods

WaitToRetryAsync(CancellationToken)

Determines whether the operation should be retried and, if so, waits for the appropriate time before the retry.
Task<bool> WaitToRetryAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken
A token that can be used to cancel the wait.

Returns

Task<bool>
A task that resolves to true if a retry should be attempted after the wait; otherwise, false.

Exceptions

OperationCanceledException
Thrown if cancellationToken is canceled while waiting.

Remarks

Implementations can base the decision on more than elapsed time and retries, such as information carried by the failure or the state of the application, and must observe cancellationToken.