Turtle.Retry 2.0.0

dotnet add package Turtle.Retry --version 2.0.0
NuGet\Install-Package Turtle.Retry -Version 2.0.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="Turtle.Retry" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Turtle.Retry --version 2.0.0
#r "nuget: Turtle.Retry, 2.0.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.
// Install Turtle.Retry as a Cake Addin
#addin nuget:?package=Turtle.Retry&version=2.0.0

// Install Turtle.Retry as a Cake Tool
#tool nuget:?package=Turtle.Retry&version=2.0.0


What does it do?

Turtle saves you from writing your logic to retry an action when it fails. It allows you to fine tune the behavior.

Why Turtle?

A turtle might be slow, but it is determined to get where it wants to be!


var result = Retry.This(() =>

This will repeat the Action passed in This() every 100ms for a maximum of 5 tries as long as the action throws an exception. result contains the CompletionState. The CompletionState is an enum with the following values: Failed, Aborted, Success.

Retry.This(() =>
    return false;

This will repeat the Func<bool> pass in This() every 100ms for a maximum of tries as long as the Func return false.

Retry.This(() => Console.WriteLine("Hello"),
        () => true)
This uses a predicate to determine if the try was successful.

Retry.This(() =>
    return false;
.Using(new LimitedExponentialBackoffRetryStrategy
    BaseDelay = TimeSpan.FromMilliseconds(50),
    MaxDelay = TimeSpan.FromSeconds(5)

This example uses a limited exponential backoff strategy. The time wait between tries increases exponentially.

Different RetryStrategies can be easily created.

var tokenSource = new CancellationTokenSource();
var t = Retry.This(() =>

It works with Tasks as well.

Control behavior based on the exception

It is possible to define how Turtle.Retry will behave in case of an exception. You can do this by passing an implementation of IExceptionBehavior like this:

Retry.This(() => action)
.OnException(new MyExceptionBehavior()

This interface is fairly simple. Just implement the OnException method, and return the appropriate AfterExceptionBehavior. AfterExceptionBehavior is an enum with the following values: Retry, Rethrow, Abort. Retry will result in another try if MaximumNumberOfTries has not been reached yet, Abort will stop the Retry process and return CompletionState.Aborted. Retrow instructs Turtle.Retry to rethrow the exception and therefore stop the Retry process.

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. 
.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
2.0.0 23,334 2/28/2018
1.1.1 1,517 10/26/2016
1.1.0 1,302 9/30/2016
1.0.1 1,340 7/12/2016
1.0.0 1,195 5/16/2016