RetryDelays 0.1.0
dotnet add package RetryDelays --version 0.1.0
NuGet\Install-Package RetryDelays -Version 0.1.0
<PackageReference Include="RetryDelays" Version="0.1.0" />
<PackageVersion Include="RetryDelays" Version="0.1.0" />
<PackageReference Include="RetryDelays" />
paket add RetryDelays --version 0.1.0
#r "nuget: RetryDelays, 0.1.0"
#:package RetryDelays@0.1.0
#addin nuget:?package=RetryDelays&version=0.1.0
#tool nuget:?package=RetryDelays&version=0.1.0
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
RetryDelayOptionstoRetryDelay - ๐งฑ Ability to create custom delay strategies using
Func<int, TimeSpan>
๐ก Key Concepts
RetryDelay: The base class responsible for calculating the exactTimeSpanto wait before the next attempt.RetryDelayOptions: Configuration objects (likeLinearRetryDelayOptionsorConstantRetryDelayOptions) 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
RetryDelaybase class can be instantiated from aFunc<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 singleRetryConfigurationsection inappsettings.jsonRetryDelayAnalysisServiceโ service that acceptsIRetryConfigurationand produces a per-attempt delay schedule and total wait time for all four strategiesGET /retry-analysis?attempts=Nโ endpoint that runs the analysis and returns the full schedule as JSON
| Product | Versions 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. |
-
.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 |