RetryDelays 0.1.0

dotnet add package RetryDelays --version 0.1.0
                    
NuGet\Install-Package RetryDelays -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RetryDelays" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RetryDelays" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="RetryDelays" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RetryDelays --version 0.1.0
                    
#r "nuget: RetryDelays, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RetryDelays@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RetryDelays&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=RetryDelays&version=0.1.0
                    
Install as a Cake Tool

RetryDelays is a lightweight .NET library for generating retry delay strategies.
Simplifies retry logic by removing the need for manual delay calculations - just use the appropriate RetryDelay or RetryDelayOptions. Supports common retry patterns such as constant, linear, exponential, and time-series delays, including jitter and decorrelated jitter.


๐Ÿš€ Quick start

Create a retry loop and let RetryDelay calculate delays between attempts.

var delay = ExponentialRetryDelay.Create(
    baseDelay: TimeSpan.FromMilliseconds(500),
    maxDelay: TimeSpan.FromSeconds(10),
    useJitter: true);

int attempt = 0;

while (attempt <= 10)
{
    try
    {
        var result = func();
        break;
    }
    catch (Exception)
    {
        attempt++;

        var nextDelay = delay.GetDelay(attempt);
        await Task.Delay(nextDelay, token);
    }
}

โญ Key Features

  • โš™๏ธ Supports multiple retry delay strategies - constant, linear, exponential, and time series
  • ๐ŸŽฒ Built-in jitter support
  • ๐Ÿ“ˆ Decorrelated jitter implementation for exponential backoff, adapted from the Polly
  • ๐Ÿงฉ Flexible configuration via RetryDelayOptions
  • ๐Ÿ”„ Implicit conversion from RetryDelayOptions to RetryDelay
  • ๐Ÿงฑ Ability to create custom delay strategies using Func<int, TimeSpan>

๐Ÿ’ก Key Concepts

  • RetryDelay: The base class responsible for calculating the exact TimeSpan to wait before the next attempt.
  • RetryDelayOptions: Configuration objects (like LinearRetryDelayOptions or ConstantRetryDelayOptions) used to define the rules of your delay strategy.
  • Attempts: Current retry attempt (an integer count starting from 0).

โœจ Available delay types

Type Description
Constant Same delay for every attempt.
Linear Delay increases linearly: (attempt + 1) * slopeFactor * baseDelay.
Exponential Delay grows exponentially: baseDelay * (exponentialFactor ^ attempt). Decorrelated jitter available.
TimeSeries Uses a predefined sequence of delays. Once exhausted, the last value repeats.

All types respect the optional MaxDelay limit.


๐ŸŽฒ Jitter Strategies

Standard Jitter - Applies ยฑ25% randomization to calculated delays to prevent synchronized retries across distributed systems.

Decorrelated Jitter - Available for exponential delays. Uses an advanced formula that produces smoother, more evenly distributed delays with fewer spikes than standard jitter. Based on techniques from Polly.


๐Ÿ› ๏ธ Passing options where a RetryDelay is expected

Thanks to implicit conversion, you can write methods that accept a RetryDelay but pass configuration options directly:

// Method that accepts a RetryDelay
async Task<T> ExecuteWithRetry<T>(
    Func<Task<T>> action,
    RetryDelay retryDelay,
    CancellationToken cancellationToken = default)
{
    int attempt = 0;
    while (true)
    {
        try
        {
            return await action();
        }
        catch
        {
            attempt++;
            var delay = retryDelay.GetDelay(attempt);
            await Task.Delay(delay, cancellationToken);
        }
    }
}

// Call the method with an options object - it is implicitly converted to the corresponding RetryDelay
var options = new ExponentialRetryDelayOptions
{
    BaseDelay = TimeSpan.FromSeconds(1),
    ExponentialFactor = 2.0,
    UseJitter = true,
    MaxDelay = TimeSpan.FromSeconds(30)
};

var result = await ExecuteWithRetry(() => FetchDataAsync(), options);

The options are automatically converted to an ExponentialRetryDelay instance, so the method receives a fully functional delay calculator.


๐Ÿ’ก Custom Delays

The RetryDelay base class is highly flexible. You can even create a delay strategy directly from a simple function:

Note: The RetryDelay base class can be instantiated from a Func<int, TimeSpan>, allowing for completely custom logic without sub-classing.

// Custom logic: delay is always (attempt * 2) seconds, but never more than 1 minute
RetryDelay customDelay = new RetryDelay(attempt => 
    TimeSpan.FromSeconds(Math.Min((attempt + 1) * 2, 60))
);

๐Ÿ“Œ When to use RetryDelays

RetryDelays focuses solely on delay calculation, allowing you to integrate it with any retry implementation or resilience framework.


๐Ÿงช Sample

The samples directory contains an ASP.NET Core Minimal API that demonstrates library usage with full configuration support.

Key highlights:

  • IRetryConfiguration โ€” interface that groups four named delay options (DelayOption1โ€“DelayOption4, covering Constant, Exponential, Linear, and TimeSeries strategies)
  • RetryConfiguration โ€” concrete implementation bound from a single RetryConfiguration section in appsettings.json
  • RetryDelayAnalysisService โ€” service that accepts IRetryConfiguration and produces a per-attempt delay schedule and total wait time for all four strategies
  • GET /retry-analysis?attempts=N โ€” endpoint that runs the analysis and returns the full schedule as JSON

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 92 7/7/2026