Struct AsyncPolicyBuilder<T1, T2>
- Namespace
- Executables.Policies
- Assembly
- executables.dll
Builds a composed asynchronous policy pipeline.
public readonly struct AsyncPolicyBuilder<T1, T2>
Type Parameters
T1Input type of the target executable.
T2Output type of the target executable.
- Inherited Members
Remarks
Policies are invoked in reverse order of addition: the last added policy executes first.
Constructors
AsyncPolicyBuilder()
Builds a composed asynchronous policy pipeline.
public AsyncPolicyBuilder()
Remarks
Policies are invoked in reverse order of addition: the last added policy executes first.
Methods
Add(AsyncPolicy<T1, T2>)
Adds a policy to the builder pipeline.
public AsyncPolicyBuilder<T1, T2> Add(AsyncPolicy<T1, T2> policy)
Parameters
policyAsyncPolicy<T1, T2>Policy to add.
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.
CancelAfterCompletion()
Adds a policy that cancels linked execution after completion.
public AsyncPolicyBuilder<T1, T2> CancelAfterCompletion()
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.
Create(AsyncFunc<T1, IAsyncExecutor<T1, T2>, T2>)
Adds an asynchronous policy created from a delegate.
public AsyncPolicyBuilder<T1, T2> Create(AsyncFunc<T1, IAsyncExecutor<T1, T2>, T2> policy)
Parameters
policyAsyncFunc<T1, IAsyncExecutor<T1, T2>, T2>Delegate implementing policy behavior.
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.
Fallback<TEx>(Func<T1, TEx, T2>)
Creates a fallback policy from a delegate.
public AsyncPolicyBuilder<T1, T2> Fallback<TEx>(Func<T1, TEx, T2> fallback) where TEx : Exception
Parameters
fallbackFunc<T1, TEx, T2>Delegate that converts input and exception into a fallback result.
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.
Type Parameters
TEx
Guard(Guard)
Adds a policy that blocks invocation when the guard denies access.
public AsyncPolicyBuilder<T1, T2> Guard(Guard guard)
Parameters
guardGuardGuard that controls whether invocation is allowed.
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.
PreventReentrance()
Adds a policy that rejects reentrant asynchronous execution.
public AsyncPolicyBuilder<T1, T2> PreventReentrance()
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.
Retry<TEx>(AsyncFunc<int, TEx, bool>)
Creates an asynchronous retry policy from a delegate rule.
public AsyncPolicyBuilder<T1, T2> Retry<TEx>(AsyncFunc<int, TEx, bool> rule) where TEx : Exception
Parameters
ruleAsyncFunc<int, TEx, bool>Delegate that receives current failed-attempt count and exception instance, and returns true to continue retrying.
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.
Type Parameters
TEx
Retry<TEx>(IRetryRule<TEx>)
Adds an asynchronous retry policy for specific exception type.
public AsyncPolicyBuilder<T1, T2> Retry<TEx>(IRetryRule<TEx> rule) where TEx : Exception
Parameters
ruleIRetryRule<TEx>Rule that decides whether the failed invocation should be retried.
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.
Type Parameters
TExException type that can trigger retries.
Timeout(TimeSpan)
Adds a timeout policy that limits total asynchronous invocation duration.
public AsyncPolicyBuilder<T1, T2> Timeout(TimeSpan timeout)
Parameters
timeoutTimeSpanMaximum allowed execution time.
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.
Validate(Validator<T1>, Validator<T2>)
Adds a policy that validates input before invocation and output after invocation.
public AsyncPolicyBuilder<T1, T2> Validate(Validator<T1> inputValidator, Validator<T2> outputValidator)
Parameters
inputValidatorValidator<T1>Validator for invocation input.
outputValidatorValidator<T2>Validator for invocation result.
Returns
- AsyncPolicyBuilder<T1, T2>
Current builder instance.