Table of Contents

Class ResiliencePipeline<T>

Namespace
Polly
Assembly
Polly.Core.dll

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

public sealed class ResiliencePipeline<T>

Type Parameters

T

The type of result this pipeline supports.

Inheritance
ResiliencePipeline<T>
Inherited Members
Extension Methods

Remarks

Resilience pipeline supports various types of callbacks of T result type and provides a unified way to execute them. This includes overloads for synchronous and asynchronous callbacks.

Fields

Empty

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

public static readonly ResiliencePipeline<T> Empty

Field Value

ResiliencePipeline<T>

Methods

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

Executes the specified callback.

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

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 the result.

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) where TResult : T

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 the result.

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) where TResult : T

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 the result.

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) where TResult : T

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 the result.

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) where TResult : T

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 the result.

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<TResult>(Func<ResilienceContext, TResult>, ResilienceContext)

Executes the specified callback.

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

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 the result.

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) where TResult : T

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 the result.

Exceptions

ArgumentNullException

Thrown when callback is null.

Execute<TResult>(Func<TResult>)

Executes the specified callback.

public TResult Execute<TResult>(Func<TResult> callback) where TResult : T

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 the result.

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) where TResult : T

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 the result.

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) where TResult : T

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 the result.

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) where TResult : T

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 the result.

TState

The type of state associated with the callback.

Exceptions

ArgumentNullException

Thrown when callback is null.