Table of Contents

AsyncTransientOperationOptions Class

Definition

Namespace
Cuemon.Resilience
Assemblies
Cuemon.Resilience.dll
Source
src/Cuemon.Resilience/AsyncTransientOperationOptions.cs

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.

// Program.cs
using System;
using System.Threading.Tasks;
using Cuemon.Resilience;
using Examples;

await new AsyncTransientOperationExample().ExecuteWithRetryAsync();

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
            Console.WriteLine(result);

    }
    }
}

Constructors

Name Description
AsyncTransientOperationOptions()

Initializes a new instance of the TransientOperationOptions class.

Properties

Name Description
CancellationToken

Gets or sets the cancellation token of an asynchronous operations.