Class AsyncTransientOperationOptions
- Namespace
- Cuemon.Resilience
- Assembly
- Cuemon.Resilience.dll
Specifies options that is related to the TransientOperation class.
public sealed class AsyncTransientOperationOptions : TransientOperationOptions, IValidatableParameterObject, IParameterObject, IAsyncOptions
- Inheritance
-
AsyncTransientOperationOptions
- Implements
- Inherited Members
Examples
The following example demonstrates how to configure retry options for an asynchronous transient operation with exponential backoff.
using System;
using System.Threading.Tasks;
using Cuemon.Resilience;
namespace Examples;
public class AsyncTransientOperationExample
{
public async Task ExecuteWithRetryAsync()
{
// Direct instantiation of AsyncTransientOperationOptions
var transientOptions = new AsyncTransientOperationOptions
{
RetryAttempts = 3,
MaximumAllowedLatency = TimeSpan.FromSeconds(30)
};
transientOptions.RetryStrategy = currentAttempt => TimeSpan.FromSeconds(Math.Pow(2, currentAttempt));
transientOptions.DetectionStrategy = exception => exception is TimeoutException;
var result = await TransientOperation.WithFuncAsync(async ct =>
{
return await Task.FromResult(42);
}, o =>
{
o.RetryAttempts = 3;
o.RetryStrategy = currentAttempt => TimeSpan.FromSeconds(Math.Pow(2, currentAttempt));
o.MaximumAllowedLatency = TimeSpan.FromSeconds(30);
o.DetectionStrategy = exception => exception is TimeoutException;
});
// result == 42 after up to 3 retries with exponential backoff
}
}
Constructors
AsyncTransientOperationOptions()
Initializes a new instance of the TransientOperationOptions class.
public AsyncTransientOperationOptions()
Remarks
The following table shows the initial property values for an instance of TransientOperationOptions.
| Property | Initial Value |
|---|---|
| CancellationToken | default |
Properties
CancellationToken
Gets or sets the cancellation token of an asynchronous operations.
public CancellationToken CancellationToken { get; set; }
Property Value
- CancellationToken
The cancellation token of an asynchronous operations.