Class LinearStrategy
- Namespace
- Kampute.HttpClient.RetryManagement.Strategies
- Assembly
- Kampute.HttpClient.dll
A retry strategy that linearly increases the delay before each retry attempt.
public sealed class LinearStrategy : IRetryStrategy
- Inheritance
-
LinearStrategy
- Implements
- Inherited Members
- Extension Methods
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
initialDelay
TimeSpanThe 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
initialDelay
TimeSpanThe initial delay duration before the first retry attempt.
delayStep
TimeSpanThe fixed amount of time by which the delay is incremented for each subsequent retry.
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
elapsed
TimeSpanThe total time elapsed since the start of retry attempts. This parameter is ignored in this implementation.
attempts
uintThe number of retry attempts made so far.
delay
TimeSpanWhen this method returns, contains the calculated delay for the next retry attempt. This parameter is passed uninitialized.