LinearStrategy Class
- Namespace
- Kampute.HttpClient.RetryManagement.Strategies
- Assembly
- Kampute.HttpClient.dll
Definition
A retry strategy that linearly increases the delay before each retry attempt.
public sealed class LinearStrategy : IRetryStrategy- Inheritance
- object
- LinearStrategy
- Implements
Remarks
The LinearStrategy class calculates the delay between retry attempts by starting with an initial delay and then increasing it linearly with each subsequent retry. This linear increment strategy offers a controlled escalation of wait times, making it suitable for scenarios where gradually backing off is preferred to reduce the load on resources or to increase the chances of a successful retry under improving conditions.
Constructors
LinearStrategy(TimeSpan)
Initializes a new instance of the LinearStrategy class with a specified initial delay.
public LinearStrategy(TimeSpan initialDelay)Parameters
initialDelayTimeSpan- The initial delay duration before the first retry attempt.
LinearStrategy(TimeSpan, TimeSpan)
Initializes a new instance of the LinearStrategy class with a specified initial delay and step increment.
public LinearStrategy(TimeSpan initialDelay, TimeSpan delayStep)Parameters
Properties
DelayStep
Gets the fixed amount of time by which the delay is increased with each retry attempt.
public TimeSpan DelayStep { get; }Property Value
- TimeSpan
- The fixed amount of time by which the delay is increased with each retry attempt.
InitialDelay
Gets the initial delay duration before the first retry attempt.
public TimeSpan InitialDelay { get; }Property Value
- TimeSpan
- The initial delay duration before the first retry attempt.
Methods
TryGetRetryDelay(TimeSpan, uint, out TimeSpan)
Calculates the delay for the next retry attempt, linearly increasing based on the number of attempts made so far.
public bool TryGetRetryDelay(TimeSpan elapsed, uint attempts, out TimeSpan delay)Parameters
elapsedTimeSpan- The total time elapsed since the start of retry attempts. This parameter is ignored in this implementation.
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. |
