TransientOperation Class
Definition
- Namespace
- Cuemon.Resilience
- Assemblies
- Cuemon.Resilience.dll
Provides a set of static methods that enable developers to make their applications more resilient by adding robust transient fault handling logic ideal for temporary condition such as network connectivity issues or service unavailability.
public static class TransientOperation
- Inheritance
-
TransientOperation
Examples
The following example shows how to execute an HTTP request with retry logic using TransientOperation. It configures three retry attempts with exponential backoff and prints the response length on success.
using System;
using System.Net.Http;
using Cuemon.Resilience;
namespace Cuemon.Resilience;
public class TransientOperationExample
{
public void Demonstrate()
{
var result = TransientOperation.WithFunc(() =>
{
using var client = new HttpClient();
return client.GetStringAsync("https://example.com").Result;
}, options =>
{
options.RetryAttempts = 3;
options.RetryStrategy = attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt));
});
Console.WriteLine($"Response length: {result.Length}");
}
}
Properties
| Name | Description |
|---|---|
| FaultCallback | Gets or sets the callback delegate that is invoked when a transient fault occurs. |
Methods
| Name | Description |
|---|---|
| WithAction(Action, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithActionAsync(Func<CancellationToken, Task>, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithActionAsync<T>(Func<T, CancellationToken, Task>, T, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithActionAsync<T1, T2>(Func<T1, T2, CancellationToken, Task>, T1, T2, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithActionAsync<T1, T2, T3>(Func<T1, T2, T3, CancellationToken, Task>, T1, T2, T3, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithActionAsync<T1, T2, T3, T4>(Func<T1, T2, T3, T4, CancellationToken, Task>, T1, T2, T3, T4, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithActionAsync<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, CancellationToken, Task>, T1, T2, T3, T4, T5, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithAction<T>(Action<T>, T, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithAction<T1, T2>(Action<T1, T2>, T1, T2, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithAction<T1, T2, T3>(Action<T1, T2, T3>, T1, T2, T3, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithAction<T1, T2, T3, T4>(Action<T1, T2, T3, T4>, T1, T2, T3, T4, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithAction<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5>, T1, T2, T3, T4, T5, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithFuncAsync<TResult>(Func<CancellationToken, Task<TResult>>, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithFuncAsync<T, TResult>(Func<T, CancellationToken, Task<TResult>>, T, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithFuncAsync<T1, T2, TResult>(Func<T1, T2, CancellationToken, Task<TResult>>, T1, T2, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithFuncAsync<T1, T2, T3, TResult>(Func<T1, T2, T3, CancellationToken, Task<TResult>>, T1, T2, T3, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithFuncAsync<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, CancellationToken, Task<TResult>>, T1, T2, T3, T4, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithFuncAsync<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, CancellationToken, Task<TResult>>, T1, T2, T3, T4, T5, Action<AsyncTransientOperationOptions>) | Repetitively executes the specified |
| WithFunc<TResult>(Func<TResult>, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithFunc<T, TResult>(Func<T, TResult>, T, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithFunc<T1, T2, TResult>(Func<T1, T2, TResult>, T1, T2, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithFunc<T1, T2, T3, TResult>(Func<T1, T2, T3, TResult>, T1, T2, T3, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithFunc<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, TResult>, T1, T2, T3, T4, Action<TransientOperationOptions>) | Repetitively executes the specified |
| WithFunc<T1, T2, T3, T4, T5, TResult>(Func<T1, T2, T3, T4, T5, TResult>, T1, T2, T3, T4, T5, Action<TransientOperationOptions>) | Repetitively executes the specified |