Table of Contents

Class ExponentialStrategy

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

A retry strategy that exponentially increases the delay before each retry attempt.

public sealed class ExponentialStrategy : IRetryStrategy
Inheritance
ExponentialStrategy
Implements
Inherited Members
Extension Methods

Remarks

The ExponentialStrategy class calculates the delay between retry attempts by starting with an initial delay and then increasing it exponentially with each subsequent retry. This strategy is effective in scenarios where the load on the underlying systems needs to be progressively reduced in the face of ongoing failures, or where it is beneficial to wait longer between attempts to increase the chance of success.

Constructors

ExponentialStrategy(TimeSpan, double)

Initializes a new instance of the ExponentialStrategy class with a specified initial delay and exponential rate.

public ExponentialStrategy(TimeSpan initialDelay, double rate)

Parameters

initialDelay TimeSpan

The initial delay duration before the first retry attempt.

rate double

The rate at which the delay duration increases exponentially between retries.

Exceptions

ArgumentOutOfRangeException

Thrown if rate is less than 1.

Properties

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.

Rate

Gets the rate at which the delay duration increases exponentially between retries.

public double Rate { get; }

Property Value

double

The rate at which the delay duration increases exponentially between retries.

Methods

TryGetRetryDelay(TimeSpan, uint, out TimeSpan)

Calculates the delay for the next retry attempt, exponentially increasing based on the number of attempts made so far.

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.