Skip to content

AsyncExecutorWithRetries Methods

This class is a convenient utility class to execute a certain asynchronous function with retries, allowing to specify custom retry filters and policies.

ExecuteWithRetries(Func<int, Task>, int, Func<Exception, int, bool>, TimeSpan, IBackoffProvider)

static
View source
public static Task ExecuteWithRetries(Func<int, Task> action, int maxNumErrorTries, Func<Exception, int, bool> retryExceptionFilter, TimeSpan maxExecutionTime, IBackoffProvider onErrorBackOff)
Execute a given function a number of times, based on retry configuration parameters.

Parameters

actionFunc<int, Task>
The action to be executed.
maxNumErrorTriesint
The maximum number of retries.
retryExceptionFilterFunc<Exception, int, bool>
The retry exception filter.
maxExecutionTimeTimeSpan
The maximum execution time.
onErrorBackOffIBackoffProvider
The backoff provider.

Returns

A System.Threading.Tasks.Task representing the operation.

ExecuteWithRetries(Func<int, Task<T>>, int, Func<Exception, int, bool>, TimeSpan, IBackoffProvider, CancellationToken)

static
View source
public static Task<T> ExecuteWithRetries<T>(Func<int, Task<T>> function, int maxNumErrorTries, Func<Exception, int, bool> retryExceptionFilter, TimeSpan maxExecutionTime, IBackoffProvider onErrorBackOff, CancellationToken cancellationToken = default(CancellationToken))
Execute a given function a number of times, based on retry configuration parameters.

Parameters

functionFunc<int, Task<T>>
The delegate to be executed.
maxNumErrorTriesint
The maximum number of retries.
retryExceptionFilterFunc<Exception, int, bool>
The retry exception filter.
maxExecutionTimeTimeSpan
The maximum execution time.
onErrorBackOffIBackoffProvider
The backoff provider.
cancellationTokenCancellationToken

Returns

The value returned from the successful invocation of the provided function.

ExecuteWithRetries(Func<int, Task<T>>, int, int, Func<T, int, bool>, Func<Exception, int, bool>, TimeSpan, IBackoffProvider, IBackoffProvider, CancellationToken)

static
View source
public static Task<T> ExecuteWithRetries<T>(Func<int, Task<T>> function, int maxNumSuccessTries, int maxNumErrorTries, Func<T, int, bool> retryValueFilter, Func<Exception, int, bool> retryExceptionFilter, TimeSpan maxExecutionTime = default(TimeSpan), IBackoffProvider onSuccessBackOff = null, IBackoffProvider onErrorBackOff = null, CancellationToken cancellationToken = default(CancellationToken))
Execute a given function a number of times, based on retry configuration parameters.

Parameters

functionFunc<int, Task<T>>
Function to execute
maxNumSuccessTriesint
Maximal number of successful execution attempts. AsyncExecutorWithRetries will try to re-execute the given function again if directed so by retryValueFilter . Set to -1 for unlimited number of success retries, until retryValueFilter is satisfied. Set to 0 for only one success attempt, which will cause retryValueFilter to be ignored and the given function executed only once until first success.
maxNumErrorTriesint
Maximal number of execution attempts due to errors. Set to -1 for unlimited number of error retries, until retryExceptionFilter is satisfied.
retryValueFilterFunc<T, int, bool>
Filter function to indicate if successful execution should be retried. Set to null to disable successful retries.
retryExceptionFilterFunc<Exception, int, bool>
Filter function to indicate if error execution should be retried. Set to null to disable error retries.
maxExecutionTimeTimeSpan
The maximal execution time of the AsyncExecutorWithRetries function.
onSuccessBackOffIBackoffProvider
The backoff provider object, which determines how much to wait between success retries.
onErrorBackOffIBackoffProvider
The backoff provider object, which determines how much to wait between error retries
cancellationTokenCancellationToken

Returns

The value returned from the successful invocation of function.