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
ContextA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
cancellationToken
CancellationTokenA 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
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether 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
CancellationTokenA 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
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether 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
ContextContext 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
CancellationTokenA 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
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether 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
action
Func<Context, CancellationToken, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA 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
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
continueOnCapturedContext
boolWhether 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
CancellationTokenA 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
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether 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
ContextContext 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
CancellationTokenA 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
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
continueOnCapturedContext
boolWhether 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>