Table of Contents

Class ResiliencePipeline

Namespace
Polly
Assembly
Polly.Core.dll

Resilience pipeline is used to execute the user-provided callbacks.

public sealed class ResiliencePipeline
Inheritance
ResiliencePipeline
Inherited Members
Extension Methods

Remarks

Resilience pipeline supports various types of callbacks and provides a unified way to execute them. This includes overloads for synchronous and asynchronous callbacks, generic and non-generic callbacks.

Fields

Empty

Resilience pipeline that executes the user-provided callback without any additional logic.

public static readonly ResiliencePipeline Empty

Field Value

ResiliencePipeline

Methods

Execute(Action)

Executes the specified callback.

public void Execute(Action callback)

Parameters

callback Action

The user-provided callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

Execute(Action<ResilienceContext>, ResilienceContext)

Executes the specified callback.

public void Execute(Action<ResilienceContext> callback, ResilienceContext context)

Parameters

callback Action<ResilienceContext>

The user-provided callback.

context ResilienceContext

The context associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback or context is null.

Execute(Action<CancellationToken>, CancellationToken)

Executes the specified callback.

public void Execute(Action<CancellationToken> callback, CancellationToken cancellationToken = default)

Parameters

callback Action<CancellationToken>

The user-provided callback.

cancellationToken CancellationToken

The CancellationToken associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

ExecuteAsync(Func<ResilienceContext, ValueTask>, ResilienceContext)

Executes the specified callback.

public ValueTask ExecuteAsync(Func<ResilienceContext, ValueTask> callback, ResilienceContext context)

Parameters

callback Func<ResilienceContext, ValueTask>

The user-provided callback.

context ResilienceContext

The context associated with the callback.

Returns

ValueTask

The instance of ValueTask that represents the asynchronous execution.

Exceptions

ArgumentNullException

Thrown when callback or context is null.

ExecuteAsync(Func<CancellationToken, ValueTask>, CancellationToken)

Executes the specified callback.

public ValueTask ExecuteAsync(Func<CancellationToken, ValueTask> callback, CancellationToken cancellationToken = default)

Parameters

callback Func<CancellationToken, ValueTask>

The user-provided callback.

cancellationToken CancellationToken

The CancellationToken associated with the callback.

Returns

ValueTask

The instance of ValueTask that represents an asynchronous callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

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

Executes the specified callback.

public ValueTask<TResult> ExecuteAsync<TResult>(Func<ResilienceContext, ValueTask<TResult>> callback, ResilienceContext context)

Parameters

callback Func<ResilienceContext, ValueTask<TResult>>

The user-provided callback.

context ResilienceContext

The context associated with the callback.

Returns

ValueTask<TResult>

The instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

Exceptions

ArgumentNullException

Thrown when callback or context is null.

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

Executes the specified callback.

public ValueTask ExecuteAsync<TState>(Func<ResilienceContext, TState, ValueTask> callback, ResilienceContext context, TState state)

Parameters

callback Func<ResilienceContext, TState, ValueTask>

The user-provided callback.

context ResilienceContext

The context associated with the callback.

state TState

The state associated with the callback.

Returns

ValueTask

The instance of ValueTask that represents the asynchronous execution.

Type Parameters

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback or context is null.

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

Executes the specified callback.

public ValueTask<TResult> ExecuteAsync<TResult>(Func<CancellationToken, ValueTask<TResult>> callback, CancellationToken cancellationToken = default)

Parameters

callback Func<CancellationToken, ValueTask<TResult>>

The user-provided callback.

cancellationToken CancellationToken

The CancellationToken associated with the callback.

Returns

ValueTask<TResult>

The instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

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

Executes the specified callback.

public ValueTask ExecuteAsync<TState>(Func<TState, CancellationToken, ValueTask> callback, TState state, CancellationToken cancellationToken = default)

Parameters

callback Func<TState, CancellationToken, ValueTask>

The user-provided callback.

state TState

The state associated with the callback.

cancellationToken CancellationToken

The CancellationToken associated with the callback.

Returns

ValueTask

The instance of ValueTask that represents an asynchronous callback.

Type Parameters

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

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

Executes the specified callback.

public ValueTask<TResult> ExecuteAsync<TResult, TState>(Func<ResilienceContext, TState, ValueTask<TResult>> callback, ResilienceContext context, TState state)

Parameters

callback Func<ResilienceContext, TState, ValueTask<TResult>>

The user-provided callback.

context ResilienceContext

The context associated with the callback.

state TState

The state associated with the callback.

Returns

ValueTask<TResult>

The instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback or context is null.

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

Executes the specified callback.

public ValueTask<TResult> ExecuteAsync<TResult, TState>(Func<TState, CancellationToken, ValueTask<TResult>> callback, TState state, CancellationToken cancellationToken = default)

Parameters

callback Func<TState, CancellationToken, ValueTask<TResult>>

The user-provided callback.

state TState

The state associated with the callback.

cancellationToken CancellationToken

The CancellationToken associated with the callback.

Returns

ValueTask<TResult>

The instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

ExecuteOutcomeAsync<TResult, TState>(Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>>, ResilienceContext, TState)

Executes the specified outcome-based callback.

public ValueTask<Outcome<TResult>> ExecuteOutcomeAsync<TResult, TState>(Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, ResilienceContext context, TState state)

Parameters

callback Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>>

The user-provided callback.

context ResilienceContext

The context associated with the callback.

state TState

The state associated with the callback.

Returns

ValueTask<Outcome<TResult>>

The instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

TState

The type of state associated with the callback.

Remarks

This method is for advanced and high performance scenarios. The caller must make sure that the callback does not throw any exceptions. Instead, it converts them to Outcome<TResult>.

Exceptions

ArgumentNullException

Thrown when callback or context is null.

Execute<TState>(Action<ResilienceContext, TState>, ResilienceContext, TState)

Executes the specified callback.

public void Execute<TState>(Action<ResilienceContext, TState> callback, ResilienceContext context, TState state)

Parameters

callback Action<ResilienceContext, TState>

The user-provided callback.

context ResilienceContext

The context associated with the callback.

state TState

The state associated with the callback.

Type Parameters

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback or context is null.

Execute<TState>(Action<TState, CancellationToken>, TState, CancellationToken)

Executes the specified callback.

public void Execute<TState>(Action<TState, CancellationToken> callback, TState state, CancellationToken cancellationToken = default)

Parameters

callback Action<TState, CancellationToken>

The user-provided callback.

state TState

The state associated with the callback.

cancellationToken CancellationToken

The CancellationToken associated with the callback.

Type Parameters

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

Execute<TState>(Action<TState>, TState)

Executes the specified callback.

public void Execute<TState>(Action<TState> callback, TState state)

Parameters

callback Action<TState>

The user-provided callback.

state TState

The state associated with the callback.

Type Parameters

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

Execute<TResult>(Func<ResilienceContext, TResult>, ResilienceContext)

Executes the specified callback.

public TResult Execute<TResult>(Func<ResilienceContext, TResult> callback, ResilienceContext context)

Parameters

callback Func<ResilienceContext, TResult>

The user-provided callback.

context ResilienceContext

The context associated with the callback.

Returns

TResult

An instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

Exceptions

ArgumentNullException

Thrown when callback or context is null.

Execute<TResult>(Func<CancellationToken, TResult>, CancellationToken)

Executes the specified callback.

public TResult Execute<TResult>(Func<CancellationToken, TResult> callback, CancellationToken cancellationToken = default)

Parameters

callback Func<CancellationToken, TResult>

The user-provided callback.

cancellationToken CancellationToken

The CancellationToken associated with the callback.

Returns

TResult

An instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

Execute<TResult>(Func<TResult>)

Executes the specified callback.

public TResult Execute<TResult>(Func<TResult> callback)

Parameters

callback Func<TResult>

The user-provided callback.

Returns

TResult

An instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

Execute<TResult, TState>(Func<ResilienceContext, TState, TResult>, ResilienceContext, TState)

Executes the specified callback.

public TResult Execute<TResult, TState>(Func<ResilienceContext, TState, TResult> callback, ResilienceContext context, TState state)

Parameters

callback Func<ResilienceContext, TState, TResult>

The user-provided callback.

context ResilienceContext

The context associated with the callback.

state TState

The state associated with the callback.

Returns

TResult

An instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback or context is null.

Execute<TResult, TState>(Func<TState, CancellationToken, TResult>, TState, CancellationToken)

Executes the specified callback.

public TResult Execute<TResult, TState>(Func<TState, CancellationToken, TResult> callback, TState state, CancellationToken cancellationToken = default)

Parameters

callback Func<TState, CancellationToken, TResult>

The user-provided callback.

state TState

The state associated with the callback.

cancellationToken CancellationToken

The CancellationToken associated with the callback.

Returns

TResult

An instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.

Execute<TResult, TState>(Func<TState, TResult>, TState)

Executes the specified callback.

public TResult Execute<TResult, TState>(Func<TState, TResult> callback, TState state)

Parameters

callback Func<TState, TResult>

The user-provided callback.

state TState

The state associated with the callback.

Returns

TResult

An instance of ValueTask that represents the asynchronous execution.

Type Parameters

TResult

The type of result returned by the callback.

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.