FibonacciStrategy Class

Namespace
Kampute.HttpClient.RetryManagement.Strategies
Assembly
  • Kampute.HttpClient.dll

Definition

A retry strategy that increases the delay before each retry attempt based on the Fibonacci sequence.
public sealed class FibonacciStrategy : IRetryStrategy
Inheritance
Implements

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 TimeSpan
The 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 TimeSpan
The initial delay duration before the first retry attempt.
delayStep TimeSpan
The 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 TimeSpan
The total time elapsed since the start of retry attempts. This parameter is ignored in this implementation.
attempts uint
The number of retry attempts made so far.
delay TimeSpan
When this method returns, contains the calculated delay for the next retry attempt. This parameter is passed uninitialized.

Returns

bool
Always returns true, indicating that a retry attempt should be made after the calculated delay.

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.