LimitedDurationStrategyModifier Class
- Namespace
- Kampute.HttpClient.RetryManagement.Strategies.Modifiers
- Assembly
- Kampute.HttpClient.dll
Definition
A retry strategy that limits the retry attempts to a specified time frame.
public sealed class LimitedDurationStrategyModifier : IRetryStrategy- Inheritance
- object
- LimitedDurationStrategyModifier
- Implements
Remarks
This class wraps another retry strategy and enforces a total time limit for retries. It ensures that the total elapsed time does not exceed the specified timeout before suggesting another retry attempt.
Constructors
LimitedDurationStrategyModifier(IRetryStrategy, TimeSpan)
Initializes a new instance of the LimitedDurationStrategyModifier class with a specified source retry strategy and timeout duration.
public LimitedDurationStrategyModifier(IRetryStrategy source, TimeSpan timeout)Parameters
sourceIRetryStrategy- The underlying retry strategy.
timeoutTimeSpan- The maximum duration to continue attempting retries before giving up.
Exceptions
- ArgumentNullException
- Thrown if
sourceisnull.
Properties
Source
Gets the underlying retry strategy, to which the specified timeout duration is applied as a limit for the total retry attempts.
public IRetryStrategy Source { get; }Property Value
- IRetryStrategy
- The underlying IRetryStrategy, to which the specified timeout duration is applied as a limit for the total retry attempts.
Timeout
Gets the maximum duration to continue attempting retries before giving up.
public TimeSpan Timeout { get; }Property Value
- TimeSpan
- The maximum duration to continue attempting retries before giving up.
Methods
TryGetRetryDelay(TimeSpan, uint, out TimeSpan)
Calculates the delay for the next retry attempt, enforcing the timeout limit.
public bool TryGetRetryDelay(TimeSpan elapsed, uint attempts, out TimeSpan delay)Parameters
elapsedTimeSpan- The total time elapsed since the start of retry attempts.
attemptsuint- The number of retry attempts made so far.
delayTimeSpan- When this method returns, contains the calculated delay for the next retry attempt. This parameter is passed uninitialized.
Returns
Extension Methods
| ToBackoffStrategy(this IRetryStrategy) | Converts an IRetryStrategy into a BackoffStrategy, creating a factory capable of producing schedulers based on the provided strategy. |
| ToScheduler(this IRetryStrategy) | Converts an IRetryStrategy into a RetryScheduler, creating a scheduler instance based on the provided strategy. |
| WithJitter(this IRetryStrategy, double) | Enhances a retry strategy with jitter to add randomness to the retry delay. |
| WithMaxAttempts(this IRetryStrategy, uint) | Enhances a retry strategy with a maximum number of retry attempts. |
| WithTimeout(this IRetryStrategy, TimeSpan) | Enhances a retry strategy with a timeout, limiting the total duration allowed for retry attempts. |
