Skip to main content

Overview

The ResiliencePipeline class is used to execute user-provided callbacks with configured resilience strategies. It provides a unified API for synchronous and asynchronous callbacks, with and without return values.

Static Properties

ResiliencePipeline
A resilience pipeline that executes the user-provided callback without any additional logic.

Synchronous Execute Methods

Execute (Action)

Executes the specified callback.
Action
required
The user-provided callback.
ArgumentNullException
Thrown when callback is null.

Execute (Action<CancellationToken>)

Executes the specified callback with a cancellation token.
Action<CancellationToken>
required
The user-provided callback.
CancellationToken
The cancellation token associated with the callback.

Execute (Action<TState>)

Executes the specified callback with state.
Action<TState>
required
The user-provided callback.
TState
The state associated with the callback.

Execute (Action<TState, CancellationToken>)

Executes the specified callback with state and cancellation token.
Action<TState, CancellationToken>
required
The user-provided callback.
TState
The state associated with the callback.
CancellationToken
The cancellation token associated with the callback.

Execute (Action<ResilienceContext>)

Executes the specified callback with a resilience context.
Action<ResilienceContext>
required
The user-provided callback.
ResilienceContext
required
The context associated with the callback.

Execute (Action<ResilienceContext, TState>)

Executes the specified callback with a resilience context and state.
Action<ResilienceContext, TState>
required
The user-provided callback.
ResilienceContext
required
The context associated with the callback.
TState
The state associated with the callback.

Synchronous Execute Methods with Result

Execute (Func<TResult>)

Executes the specified callback and returns a result.
Func<TResult>
required
The user-provided callback.
TResult
The result of the callback execution.

Execute (Func<CancellationToken, TResult>)

Executes the specified callback with a cancellation token and returns a result.
Func<CancellationToken, TResult>
required
The user-provided callback.
CancellationToken
The cancellation token associated with the callback.
TResult
The result of the callback execution.

Execute (Func<TState, TResult>)

Executes the specified callback with state and returns a result.
Func<TState, TResult>
required
The user-provided callback.
TState
The state associated with the callback.
TResult
The result of the callback execution.

Execute (Func<TState, CancellationToken, TResult>)

Executes the specified callback with state and cancellation token and returns a result.
Func<TState, CancellationToken, TResult>
required
The user-provided callback.
TState
The state associated with the callback.
CancellationToken
The cancellation token associated with the callback.
TResult
The result of the callback execution.

Execute (Func<ResilienceContext, TResult>)

Executes the specified callback with a resilience context and returns a result.
Func<ResilienceContext, TResult>
required
The user-provided callback.
ResilienceContext
required
The context associated with the callback.
TResult
The result of the callback execution.

Execute (Func<ResilienceContext, TState, TResult>)

Executes the specified callback with a resilience context and state and returns a result.
Func<ResilienceContext, TState, TResult>
required
The user-provided callback.
ResilienceContext
required
The context associated with the callback.
TState
The state associated with the callback.
TResult
The result of the callback execution.

Asynchronous Execute Methods

ExecuteAsync (Func<CancellationToken, ValueTask>)

Executes the specified asynchronous callback.
Func<CancellationToken, ValueTask>
required
The user-provided callback.
CancellationToken
The cancellation token associated with the callback.
ValueTask
A task that represents the asynchronous execution.

ExecuteAsync (Func<TState, CancellationToken, ValueTask>)

Executes the specified asynchronous callback with state.
Func<TState, CancellationToken, ValueTask>
required
The user-provided callback.
TState
The state associated with the callback.
CancellationToken
The cancellation token associated with the callback.
ValueTask
A task that represents the asynchronous execution.

ExecuteAsync (Func<ResilienceContext, ValueTask>)

Executes the specified asynchronous callback with a resilience context.
Func<ResilienceContext, ValueTask>
required
The user-provided callback.
ResilienceContext
required
The context associated with the callback.
ValueTask
A task that represents the asynchronous execution.

ExecuteAsync (Func<ResilienceContext, TState, ValueTask>)

Executes the specified asynchronous callback with a resilience context and state.
Func<ResilienceContext, TState, ValueTask>
required
The user-provided callback.
ResilienceContext
required
The context associated with the callback.
TState
The state associated with the callback.
ValueTask
A task that represents the asynchronous execution.

Asynchronous Execute Methods with Result

ExecuteAsync (Func<CancellationToken, ValueTask<TResult>>)

Executes the specified asynchronous callback and returns a result.
Func<CancellationToken, ValueTask<TResult>>
required
The user-provided callback.
CancellationToken
The cancellation token associated with the callback.
ValueTask<TResult>
A task that represents the asynchronous execution and returns the result.

ExecuteAsync (Func<TState, CancellationToken, ValueTask<TResult>>)

Executes the specified asynchronous callback with state and returns a result.
Func<TState, CancellationToken, ValueTask<TResult>>
required
The user-provided callback.
TState
The state associated with the callback.
CancellationToken
The cancellation token associated with the callback.
ValueTask<TResult>
A task that represents the asynchronous execution and returns the result.

ExecuteAsync (Func<ResilienceContext, ValueTask<TResult>>)

Executes the specified asynchronous callback with a resilience context and returns a result.
Func<ResilienceContext, ValueTask<TResult>>
required
The user-provided callback.
ResilienceContext
required
The context associated with the callback.
ValueTask<TResult>
A task that represents the asynchronous execution and returns the result.

ExecuteAsync (Func<ResilienceContext, TState, ValueTask<TResult>>)

Executes the specified asynchronous callback with a resilience context and state and returns a result.
Func<ResilienceContext, TState, ValueTask<TResult>>
required
The user-provided callback.
ResilienceContext
required
The context associated with the callback.
TState
The state associated with the callback.
ValueTask<TResult>
A task that represents the asynchronous execution and returns the result.

Advanced Execute Methods

ExecuteOutcomeAsync

Executes the specified outcome-based callback for advanced, low-allocation scenarios.
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>>
required
The user-provided callback that returns an Outcome<TResult>.
ResilienceContext
required
The context associated with the callback.
TState
The state associated with the callback.
ValueTask<Outcome<TResult>>
A task that represents the asynchronous execution and returns the outcome.
The user callback must not throw an exception. Wrap your code and return Outcome<TResult>: use Outcome.FromResult<TResult>(TResult) on success, or Outcome.FromException<TResult>(Exception) on failure. Do not rely on strategies to catch your exceptions.

ResiliencePipeline<T>

A generic version of ResiliencePipeline that constrains result types to T.

Static Properties

ResiliencePipeline<T>
A resilience pipeline that executes the user-provided callback without any additional logic.

Execute Methods

All execute methods from ResiliencePipeline are available with an additional constraint that TResult : T.

Example Usage

Generic Pipeline Example