Table of Contents

Interface IAsyncPolicy

Namespace
Polly
Assembly
Polly.dll

An interface defining all executions available on a non-generic, asynchronous policy

public interface IAsyncPolicy : IsPolicy
Inherited Members

Methods

ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task>, Context, CancellationToken)

Executes the specified asynchronous action within the policy and returns the captured result.

Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken)

Parameters

action Func<Context, CancellationToken, Task>

The action to perform.

context Context

Context data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task<PolicyResult>

ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task>, Context, CancellationToken, bool)

Executes the specified asynchronous action within the policy and returns the captured result.

Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<Context, CancellationToken, Task>

The action to perform.

context Context

Context data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task<PolicyResult>

Exceptions

InvalidOperationException

Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.

ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task>, IDictionary<string, object>, CancellationToken)

Executes the specified asynchronous action within the policy and returns the captured result.

Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)

Parameters

action Func<Context, CancellationToken, Task>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task<PolicyResult>

The captured result

Exceptions

ArgumentNullException

contextData

ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task>, IDictionary<string, object>, CancellationToken, bool)

Executes the specified asynchronous action within the policy and returns the captured result.

Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task> action, IDictionary<string, object> contextData, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<Context, CancellationToken, Task>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task<PolicyResult>

The captured result

Exceptions

ArgumentNullException

contextData

ExecuteAndCaptureAsync(Func<Context, Task>, Context)

Executes the specified asynchronous action within the policy and returns the captured result.

Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, Task> action, Context context)

Parameters

action Func<Context, Task>

The action to perform.

context Context

Context data that is passed to the exception policy.

Returns

Task<PolicyResult>

The captured result

ExecuteAndCaptureAsync(Func<Context, Task>, IDictionary<string, object>)

Executes the specified asynchronous action within the policy and returns the captured result.

Task<PolicyResult> ExecuteAndCaptureAsync(Func<Context, Task> action, IDictionary<string, object> contextData)

Parameters

action Func<Context, Task>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

Returns

Task<PolicyResult>

The captured result

Exceptions

ArgumentNullException

contextData

ExecuteAndCaptureAsync(Func<CancellationToken, Task>, CancellationToken)

Executes the specified asynchronous action within the policy and returns the captured result.

Task<PolicyResult> ExecuteAndCaptureAsync(Func<CancellationToken, Task> action, CancellationToken cancellationToken)

Parameters

action Func<CancellationToken, Task>

The action to perform.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task<PolicyResult>

ExecuteAndCaptureAsync(Func<CancellationToken, Task>, CancellationToken, bool)

Executes the specified asynchronous action within the policy and returns the captured result.

Task<PolicyResult> ExecuteAndCaptureAsync(Func<CancellationToken, Task> action, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<CancellationToken, Task>

The action to perform.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task<PolicyResult>

Exceptions

InvalidOperationException

Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.

ExecuteAndCaptureAsync(Func<Task>)

Executes the specified asynchronous action within the policy and returns the captured result.

Task<PolicyResult> ExecuteAndCaptureAsync(Func<Task> action)

Parameters

action Func<Task>

The action to perform.

Returns

Task<PolicyResult>

The captured result

ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken)

Executes the specified asynchronous action within the policy and returns the result.

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken)

Parameters

action Func<Context, CancellationToken, Task<TResult>>

The action to perform.

context Context

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task<PolicyResult<TResult>>

The captured result

Type Parameters

TResult

The type of the result.

ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken, bool)

Executes the specified asynchronous action within the policy and returns the result.

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<Context, CancellationToken, Task<TResult>>

The action to perform.

context Context

Context data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task<PolicyResult<TResult>>

The captured result

Type Parameters

TResult

The type of the result.

Exceptions

InvalidOperationException

Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.

ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken)

Executes the specified asynchronous action within the policy and returns the result.

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)

Parameters

action Func<Context, CancellationToken, Task<TResult>>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task<PolicyResult<TResult>>

The captured result

Type Parameters

TResult

The type of the result.

Exceptions

ArgumentNullException

contextData

ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken, bool)

Executes the specified asynchronous action within the policy and returns the result.

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<Context, CancellationToken, Task<TResult>>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task<PolicyResult<TResult>>

The captured result

Type Parameters

TResult

The type of the result.

Exceptions

ArgumentNullException

contextData

ExecuteAndCaptureAsync<TResult>(Func<Context, Task<TResult>>, Context)

Executes the specified asynchronous action within the policy and returns the result.

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context, Task<TResult>> action, Context context)

Parameters

action Func<Context, Task<TResult>>

The action to perform.

context Context

Context data that is passed to the exception policy.

Returns

Task<PolicyResult<TResult>>

The captured result

Type Parameters

TResult

The type of the result.

ExecuteAndCaptureAsync<TResult>(Func<Context, Task<TResult>>, IDictionary<string, object>)

Executes the specified asynchronous action within the policy and returns the result.

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Context, Task<TResult>> action, IDictionary<string, object> contextData)

Parameters

action Func<Context, Task<TResult>>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

Returns

Task<PolicyResult<TResult>>

The captured result

Type Parameters

TResult

The type of the result.

Exceptions

ArgumentNullException

contextData

ExecuteAndCaptureAsync<TResult>(Func<CancellationToken, Task<TResult>>, CancellationToken)

Executes the specified asynchronous action within the policy and returns the result.

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken)

Parameters

action Func<CancellationToken, Task<TResult>>

The action to perform.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task<PolicyResult<TResult>>

The captured result

Type Parameters

TResult

The type of the result.

ExecuteAndCaptureAsync<TResult>(Func<CancellationToken, Task<TResult>>, CancellationToken, bool)

Executes the specified asynchronous action within the policy and returns the result.

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<CancellationToken, Task<TResult>>

The action to perform.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task<PolicyResult<TResult>>

The captured result

Type Parameters

TResult

The type of the result.

Exceptions

InvalidOperationException

Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.

ExecuteAndCaptureAsync<TResult>(Func<Task<TResult>>)

Executes the specified asynchronous action within the policy and returns the result.

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync<TResult>(Func<Task<TResult>> action)

Parameters

action Func<Task<TResult>>

The action to perform.

Returns

Task<PolicyResult<TResult>>

The captured result

Type Parameters

TResult

The type of the result.

ExecuteAsync(Func<Context, CancellationToken, Task>, Context, CancellationToken)

Executes the specified asynchronous action within the policy.

Task ExecuteAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken)

Parameters

action Func<Context, CancellationToken, Task>

The action to perform.

context Context

Context data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task

ExecuteAsync(Func<Context, CancellationToken, Task>, Context, CancellationToken, bool)

Executes the specified asynchronous action within the policy.

Task ExecuteAsync(Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<Context, CancellationToken, Task>

The action to perform.

context Context

Context data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task

Exceptions

InvalidOperationException

Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.

ExecuteAsync(Func<Context, CancellationToken, Task>, IDictionary<string, object>, CancellationToken)

Executes the specified asynchronous action within the policy.

Task ExecuteAsync(Func<Context, CancellationToken, Task> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)

Parameters

action Func<Context, CancellationToken, Task>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task

ExecuteAsync(Func<Context, CancellationToken, Task>, IDictionary<string, object>, CancellationToken, bool)

Executes the specified asynchronous action within the policy.

Task ExecuteAsync(Func<Context, CancellationToken, Task> action, IDictionary<string, object> contextData, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<Context, CancellationToken, Task>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task

Exceptions

ArgumentNullException

contextData

ExecuteAsync(Func<Context, Task>, Context)

Executes the specified asynchronous action within the policy.

Task ExecuteAsync(Func<Context, Task> action, Context context)

Parameters

action Func<Context, Task>

The action to perform.

context Context

Context data that is passed to the exception policy.

Returns

Task

ExecuteAsync(Func<Context, Task>, IDictionary<string, object>)

Executes the specified asynchronous action within the policy.

Task ExecuteAsync(Func<Context, Task> action, IDictionary<string, object> contextData)

Parameters

action Func<Context, Task>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

Returns

Task

ExecuteAsync(Func<CancellationToken, Task>, CancellationToken)

Executes the specified asynchronous action within the policy.

Task ExecuteAsync(Func<CancellationToken, Task> action, CancellationToken cancellationToken)

Parameters

action Func<CancellationToken, Task>

The action to perform.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task

ExecuteAsync(Func<CancellationToken, Task>, CancellationToken, bool)

Executes the specified asynchronous action within the policy.

Task ExecuteAsync(Func<CancellationToken, Task> action, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<CancellationToken, Task>

The action to perform.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task

Exceptions

InvalidOperationException

Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.

ExecuteAsync(Func<Task>)

Executes the specified asynchronous action within the policy.

Task ExecuteAsync(Func<Task> action)

Parameters

action Func<Task>

The action to perform.

Returns

Task

ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken)

Executes the specified asynchronous action within the policy and returns the result.

Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken)

Parameters

action Func<Context, CancellationToken, Task<TResult>>

The action to perform.

context Context

Context data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.

Returns

Task<TResult>

The value returned by the action

Type Parameters

TResult

The type of the result.

ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken, bool)

Executes the specified asynchronous action within the policy and returns the result.

Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<Context, CancellationToken, Task<TResult>>

The action to perform.

context Context

Context data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task<TResult>

The value returned by the action

Type Parameters

TResult

The type of the result.

Exceptions

InvalidOperationException

Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.

ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken)

Executes the specified asynchronous action within the policy and returns the result.

Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)

Parameters

action Func<Context, CancellationToken, Task<TResult>>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

Returns

Task<TResult>

The value returned by the action

Type Parameters

TResult

ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken, bool)

Executes the specified asynchronous action within the policy and returns the result.

Task<TResult> ExecuteAsync<TResult>(Func<Context, CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<Context, CancellationToken, Task<TResult>>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task<TResult>

The value returned by the action

Type Parameters

TResult

Exceptions

ArgumentNullException

contextData

ExecuteAsync<TResult>(Func<Context, Task<TResult>>, Context)

Executes the specified asynchronous action within the policy and returns the result.

Task<TResult> ExecuteAsync<TResult>(Func<Context, Task<TResult>> action, Context context)

Parameters

action Func<Context, Task<TResult>>

The action to perform.

context Context

Context data that is passed to the exception policy.

Returns

Task<TResult>

The value returned by the action

Type Parameters

TResult

The type of the result.

ExecuteAsync<TResult>(Func<Context, Task<TResult>>, IDictionary<string, object>)

Executes the specified asynchronous action within the policy and returns the result.

Task<TResult> ExecuteAsync<TResult>(Func<Context, Task<TResult>> action, IDictionary<string, object> contextData)

Parameters

action Func<Context, Task<TResult>>

The action to perform.

contextData IDictionary<string, object>

Arbitrary data that is passed to the exception policy.

Returns

Task<TResult>

The value returned by the action

Type Parameters

TResult

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

Executes the specified asynchronous action within the policy and returns the result.

Task<TResult> ExecuteAsync<TResult>(Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken)

Parameters

action Func<CancellationToken, Task<TResult>>

The action to perform.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.

Returns

Task<TResult>

The value returned by the action

Type Parameters

TResult

The type of the result.

ExecuteAsync<TResult>(Func<CancellationToken, Task<TResult>>, CancellationToken, bool)

Executes the specified asynchronous action within the policy and returns the result.

Task<TResult> ExecuteAsync<TResult>(Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken, bool continueOnCapturedContext)

Parameters

action Func<CancellationToken, Task<TResult>>

The action to perform.

cancellationToken CancellationToken

A cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.

continueOnCapturedContext bool

Whether to continue on a captured synchronization context.

Returns

Task<TResult>

The value returned by the action

Type Parameters

TResult

The type of the result.

Exceptions

InvalidOperationException

Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.

ExecuteAsync<TResult>(Func<Task<TResult>>)

Executes the specified asynchronous action within the policy and returns the result.

Task<TResult> ExecuteAsync<TResult>(Func<Task<TResult>> action)

Parameters

action Func<Task<TResult>>

The action to perform.

Returns

Task<TResult>

The value returned by the action

Type Parameters

TResult

The type of the result.

WithPolicyKey(string)

Sets the PolicyKey for this Policy instance. Must be called before the policy is first used. Can only be set once.

IAsyncPolicy WithPolicyKey(string policyKey)

Parameters

policyKey string

The unique, used-definable key to assign to this Policy instance.

Returns

IAsyncPolicy