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
TResultThe 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
actionFunc<Context, CancellationToken, Task<TResult>>The action to perform.
contextContextA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
cancellationTokenCancellationTokenA 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
actionFunc<Context, CancellationToken, Task<TResult>>The action to perform.
contextContextContext data that is passed to the exception policy.
cancellationTokenCancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContextboolWhether 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
actionFunc<Context, CancellationToken, Task<TResult>>The action to perform.
contextDataIDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationTokenCancellationTokenA 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
actionFunc<Context, CancellationToken, Task<TResult>>The action to perform.
contextDataIDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationTokenCancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContextboolWhether 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
actionFunc<Context, Task<TResult>>The action to perform.
contextContextContext 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
actionFunc<Context, Task<TResult>>The action to perform.
contextDataIDictionary<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
actionFunc<CancellationToken, Task<TResult>>The action to perform.
cancellationTokenCancellationTokenA 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
actionFunc<CancellationToken, Task<TResult>>The action to perform.
cancellationTokenCancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContextboolWhether 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
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
actionFunc<Context, CancellationToken, Task<TResult>>The action to perform.
contextContextContext data that is passed to the exception policy.
cancellationTokenCancellationTokenA 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
actionFunc<Context, CancellationToken, Task<TResult>>The action to perform.
contextContextContext data that is passed to the exception policy.
cancellationTokenCancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
continueOnCapturedContextboolWhether 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
actionFunc<Context, CancellationToken, Task<TResult>>The action to perform.
contextDataIDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationTokenCancellationTokenA 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
actionFunc<Context, CancellationToken, Task<TResult>>The action to perform.
contextDataIDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationTokenCancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContextboolWhether 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
actionFunc<Context, Task<TResult>>The action to perform.
contextContextContext 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
actionFunc<Context, Task<TResult>>The action to perform.
contextDataIDictionary<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
actionFunc<CancellationToken, Task<TResult>>The action to perform.
cancellationTokenCancellationTokenA 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
actionFunc<CancellationToken, Task<TResult>>The action to perform.
cancellationTokenCancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
continueOnCapturedContextboolWhether 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
Returns
- Task<TResult>
The value returned by the action
WithPolicyKey(string)
Sets the PolicyKey for this Policy instance.
IAsyncPolicy<TResult> WithPolicyKey(string policyKey)
Parameters
Returns
- IAsyncPolicy<TResult>