ErrorComponents 1.0.2

Components for fault-tolerant error handling.

Install-Package ErrorComponents -Version 1.0.2
dotnet add package ErrorComponents --version 1.0.2
<PackageReference Include="ErrorComponents" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ErrorComponents --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

ErrorComponents

The ErrorComponents library is a set of fault tolerant wrapper classes around Action, Action<T>, Func<TResult>, Func<T, TResult>...
The wrapper classes offer a retry mechanism in case of an exception. Retry interval can be set to be linear or exponential.

It contains the following wrapper classes:

FaultTolerantAction
FaultTolerantAction<T>
FaultTolerantAction<T1, T2>
FaultTolerantFunc<TResult>
FaultTolerantFunc<T, TResult>

Usage

int invocationCounter = 0;
var sw = new Stopwatch();

// This action will fail with an exception:
var error = new Action(() =>
{
    invocationCounter++;
    Console.WriteLine("Invocation " + invocationCounter);
    throw new NotImplementedException();
});

// Initialize a wrapper class, which will try to invoke the
// action 5 times before giving up. The default delay
// between invocations is one second:
var retry = new FaultTolerantAction(error, 5);

sw.Start();
var success = retry.Invoke();
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);

// Initialize a wrapper class, which will try to invoke the
// action 5 times before giving up. The default delay
// between invocations increases exponentially:
var retry2 = new FaultTolerantAction(error, 5, new ExponentialRetryStrategy(1000));

sw.Start();
retry2.Invoke();
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);

// Initialize a wrapper class, which will try to invoke the
// action 5 times before giving up, when the exception message
ends with 1 or 2:
var retry3 = new FaultTolerantAction(error, 5)
    .Filter(e => e.Message.EndsWith("1") || e.Message.EndsWith("2"));

sw.Start();
retry3.Invoke();
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);

More examples can be found on Github

ErrorComponents

The ErrorComponents library is a set of fault tolerant wrapper classes around Action, Action<T>, Func<TResult>, Func<T, TResult>...
The wrapper classes offer a retry mechanism in case of an exception. Retry interval can be set to be linear or exponential.

It contains the following wrapper classes:

FaultTolerantAction
FaultTolerantAction<T>
FaultTolerantAction<T1, T2>
FaultTolerantFunc<TResult>
FaultTolerantFunc<T, TResult>

Usage

int invocationCounter = 0;
var sw = new Stopwatch();

// This action will fail with an exception:
var error = new Action(() =>
{
    invocationCounter++;
    Console.WriteLine("Invocation " + invocationCounter);
    throw new NotImplementedException();
});

// Initialize a wrapper class, which will try to invoke the
// action 5 times before giving up. The default delay
// between invocations is one second:
var retry = new FaultTolerantAction(error, 5);

sw.Start();
var success = retry.Invoke();
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);

// Initialize a wrapper class, which will try to invoke the
// action 5 times before giving up. The default delay
// between invocations increases exponentially:
var retry2 = new FaultTolerantAction(error, 5, new ExponentialRetryStrategy(1000));

sw.Start();
retry2.Invoke();
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);

// Initialize a wrapper class, which will try to invoke the
// action 5 times before giving up, when the exception message
ends with 1 or 2:
var retry3 = new FaultTolerantAction(error, 5)
    .Filter(e => e.Message.EndsWith("1") || e.Message.EndsWith("2"));

sw.Start();
retry3.Invoke();
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);

More examples can be found on Github

  • .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 History

Version Downloads Last updated
1.0.2 149 5/1/2020
1.0.1 124 4/22/2020
1.0.0 114 4/21/2020