Table of Contents

Struct AsyncPolicyBuilder<T1, T2>

Namespace
Executables.Policies
Assembly
executables.dll

Builds a composed asynchronous policy pipeline.

public readonly struct AsyncPolicyBuilder<T1, T2>

Type Parameters

T1

Input type of the target executable.

T2

Output 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

policy AsyncPolicy<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

policy AsyncFunc<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

fallback Func<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

guard Guard

Guard 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

rule AsyncFunc<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

rule IRetryRule<TEx>

Rule that decides whether the failed invocation should be retried.

Returns

AsyncPolicyBuilder<T1, T2>

Current builder instance.

Type Parameters

TEx

Exception 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

timeout TimeSpan

Maximum 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

inputValidator Validator<T1>

Validator for invocation input.

outputValidator Validator<T2>

Validator for invocation result.

Returns

AsyncPolicyBuilder<T1, T2>

Current builder instance.