Imato.Try 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Imato.Try --version 1.0.1
NuGet\Install-Package Imato.Try -Version 1.0.1
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="Imato.Try" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Imato.Try --version 1.0.1
#r "nuget: Imato.Try, 1.0.1"
#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 Imato.Try as a Cake Addin
#addin nuget:?package=Imato.Try&version=1.0.1

// Install Imato.Try as a Cake Tool
#tool nuget:?package=Imato.Try&version=1.0.1

Imato.Try

Simple try-retry strategy

Try
using Imato.Try;

// Execution options
var options = new TryOptions
{
    RetryCount = 3,
    Delay = 20,
    Timeout = 2000
};

// Function to execute
var testFunc1 = (int id) =>
{
    if (id % 2 == 0)
    {
        return Task.FromResult(id);
    }
    throw new ArgumentException(nameof(id));
};

// Default behavior
var result = await Try
    .Function(() => testFunc1(2))
    .GetResultAsync();

// Add exception handler
result = await Try
    .Function(() => testFunc1(2))
    .OnError((ex) => Console.WriteLine(ex.Message))
    .GetResultAsync();

// With retry and over options
result = await Try
    .Function(() => testFunc1(2))
    .Setup(options)
    .OnError((ex) => Console.WriteLine(ex.Message))
    .GetResultAsync();

// Without result
var errorCount = 0;
await Try
    .Function(() => testFunc2(1))
    .Function(() => testFunc2(2))
    .Function(() => testFunc2(3))
    .OnError((ex) => errorCount++)
    .OnError((ex) => Console.WriteLine(ex.Message))
    .Setup(options)
    .Execute();

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Imato.Try:

Package Downloads
Imato.Api.Request

Utils for using REST API

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 707 1/11/2023
1.0.3 310 11/25/2022
1.0.2 470 11/21/2022
1.0.1 290 11/21/2022
1.0.0 286 11/21/2022

Ready to use