Class FibonacciStrategy
- Namespace
- Kampute.HttpClient.RetryManagement.Strategies
- Assembly
- Kampute.HttpClient.dll
A retry strategy that increases the delay before each retry attempt based on the Fibonacci sequence.
public sealed class FibonacciStrategy : IRetryStrategy
- Inheritance
-
FibonacciStrategy
- Implements
- Inherited Members
- Extension Methods
Remarks
The FibonacciStrategy class uses the Fibonacci sequence to adjust the wait time between retries, starting with an initial delay and scaling the delay between subsequent attempts according to Fibonacci numbers. This approach provides a more moderate and controlled increase in delay times compared to the ExponentialStrategy approach, making it suitable for scenarios where a less aggressive increase in delay is desired.
Constructors
FibonacciStrategy(TimeSpan)
Initializes a new instance of the FibonacciStrategy class with a specified initial delay.
public FibonacciStrategy(TimeSpan initialDelay)
Parameters
initialDelay
TimeSpanThe initial delay duration before the first retry attempt.
FibonacciStrategy(TimeSpan, TimeSpan)
Initializes a new instance of the FibonacciStrategy class with a specified initial delay and step increment.
public FibonacciStrategy(TimeSpan initialDelay, TimeSpan delayStep)
Parameters
initialDelay
TimeSpanThe initial delay duration before the first retry attempt.
delayStep
TimeSpanThe fixed amount of time that is scaled by the Fibonacci sequence and added to the initial delay for each subsequent retry attempt.
Properties
DelayStep
Gets the fixed amount of time that is scaled by the Fibonacci sequence and added to the initial delay for each subsequent retry attempt.
public TimeSpan DelayStep { get; }
Property Value
- TimeSpan
The fixed amount of time that is scaled by the Fibonacci sequence and added to the initial delay for each subsequent 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 based on the Fibonacci sequence.
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.