Table of Contents

Interface IAsyncPolicy<TResult>

Namespace
Polly
Assembly
Polly.dll

An interface defining all executions available on an asynchronous policy generic-typed for executions returning results of type TResult.

public interface IAsyncPolicy<TResult> : IsPolicy

Type Parameters

TResult

The type of the result of funcs executed through the Policy.

Inherited Members

Methods

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

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

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(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

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

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

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(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

Exceptions

InvalidOperationException

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

ExecuteAndCaptureAsync(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(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

Exceptions

ArgumentNullException

contextData

ExecuteAndCaptureAsync(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(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

Exceptions

ArgumentNullException

contextData

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

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

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(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

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

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

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(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

Exceptions

ArgumentNullException

contextData

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

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

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(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

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

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

Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(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

Exceptions

InvalidOperationException

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

ExecuteAndCaptureAsync(Func<Task<TResult>>)

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

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

Parameters

action Func<Task<TResult>>

The action to perform.

Returns

Task<PolicyResult<TResult>>

The captured result

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

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

Task<TResult> ExecuteAsync(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

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

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

Task<TResult> ExecuteAsync(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

Exceptions

InvalidOperationException

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

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

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

Task<TResult> ExecuteAsync(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

ExecuteAsync(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(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

Exceptions

ArgumentNullException

contextData

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

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

Task<TResult> ExecuteAsync(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

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

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

Task<TResult> ExecuteAsync(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

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

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

Task<TResult> ExecuteAsync(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

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

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

Task<TResult> ExecuteAsync(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

Exceptions

InvalidOperationException

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

ExecuteAsync(Func<Task<TResult>>)

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

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

Parameters

action Func<Task<TResult>>

The action to perform.

Returns

Task<TResult>

The value returned by the action

WithPolicyKey(string)

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

IAsyncPolicy<TResult> WithPolicyKey(string policyKey)

Parameters

policyKey string

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

Returns

IAsyncPolicy<TResult>