Table of Contents

Class AsyncPolicyBase<TModel, TMetadata>

Namespace
Motiv
Assembly
Motiv.dll

The base class for asynchronous policies. A policy is a specification that resolves to a single value — one assertion or one metadata object per evaluation. Mirrors PolicyBase<TModel, TMetadata>.

public abstract class AsyncPolicyBase<TModel, TMetadata> : AsyncSpecBase<TModel, TMetadata>

Type Parameters

TModel

The model type that the policy will evaluate against

TMetadata

The type of the metadata to associate with the predicate

Inheritance
AsyncSpecBase<TModel, TMetadata>
AsyncPolicyBase<TModel, TMetadata>
Inherited Members
Extension Methods

Methods

AndAlso(AsyncPolicyBase<TModel, TMetadata>)

Creates a new asynchronous policy that is equivalent to a conditional "AND" of the current policy and the other policy, preserving the single-value policy guarantee. The other policy's work is only started if this policy is satisfied.

public AsyncPolicyBase<TModel, TMetadata> AndAlso(AsyncPolicyBase<TModel, TMetadata> other)

Parameters

other AsyncPolicyBase<TModel, TMetadata>

The asynchronous policy to evaluate in the event that this policy is satisfied

Returns

AsyncPolicyBase<TModel, TMetadata>

A new AsyncPolicyBase<TModel, TMetadata> that will perform the conditional "And" operation between this and other when the policy is eventually evaluated.

AndAlso(PolicyBase<TModel, TMetadata>)

Combines this policy with a synchronous policy using the conditional AND operator, preserving the policy guarantee. The synchronous other operand is lifted into the asynchronous hierarchy via ToAsyncSpec(). The other operand's work is only started if this policy is satisfied.

public AsyncPolicyBase<TModel, TMetadata> AndAlso(PolicyBase<TModel, TMetadata> other)

Parameters

other PolicyBase<TModel, TMetadata>

The synchronous policy to evaluate in the event that this policy is satisfied.

Returns

AsyncPolicyBase<TModel, TMetadata>

A new policy that represents the conditional AND of this policy and other.

EvaluateAsync(TModel, CancellationToken)

Asynchronously evaluates the policy against the model and returns a result that contains the Boolean result of the predicate in addition to a single metadata value.

public ValueTask<PolicyResultBase<TMetadata>> EvaluateAsync(TModel model, CancellationToken cancellationToken = default)

Parameters

model TModel

The model to evaluate the policy against.

cancellationToken CancellationToken

A token that can cancel the evaluation.

Returns

ValueTask<PolicyResultBase<TMetadata>>

A result that contains the Boolean result of the predicate in addition to the metadata.

EvaluatePolicyAsync(TModel, CancellationToken)

Asynchronously evaluates the policy against the model.

protected abstract ValueTask<PolicyResultBase<TMetadata>> EvaluatePolicyAsync(TModel model, CancellationToken cancellationToken)

Parameters

model TModel

The model to evaluate the policy against.

cancellationToken CancellationToken

A token that can cancel the evaluation.

Returns

ValueTask<PolicyResultBase<TMetadata>>

A result that contains the Boolean result of the predicate in addition to the metadata.

EvaluateSpecAsync(TModel, CancellationToken)

Asynchronously evaluates the specification against the model and returns a result that contains the Boolean result of the predicate in addition to the metadata.

protected override ValueTask<BooleanResultBase<TMetadata>> EvaluateSpecAsync(TModel model, CancellationToken cancellationToken)

Parameters

model TModel

The model to evaluate the specification against.

cancellationToken CancellationToken

A token that can cancel the evaluation.

Returns

ValueTask<BooleanResultBase<TMetadata>>

A result that contains the Boolean result of the predicate in addition to the metadata.

Not()

Negates this policy.

public AsyncPolicyBase<TModel, TMetadata> Not()

Returns

AsyncPolicyBase<TModel, TMetadata>

A new policy that represents the logical NOT of this policy.

OrElse(AsyncPolicyBase<TModel, TMetadata>)

Combines this policy with another policy using the conditional OR operator, preserving the policy guarantee. The right operand is only evaluated if the left operand resolves to false.

public AsyncPolicyBase<TModel, TMetadata> OrElse(AsyncPolicyBase<TModel, TMetadata> alternative)

Parameters

alternative AsyncPolicyBase<TModel, TMetadata>

The fallback policy.

Returns

AsyncPolicyBase<TModel, TMetadata>

A new policy that represents the conditional OR of this policy and the alternative.

OrElse(PolicyBase<TModel, TMetadata>)

Combines this policy with a synchronous policy using the conditional OR operator, preserving the policy guarantee. The synchronous alternative is lifted into the asynchronous hierarchy via ToAsyncSpec(). The right operand is only evaluated if the left operand resolves to false.

public AsyncPolicyBase<TModel, TMetadata> OrElse(PolicyBase<TModel, TMetadata> alternative)

Parameters

alternative PolicyBase<TModel, TMetadata>

The synchronous fallback policy.

Returns

AsyncPolicyBase<TModel, TMetadata>

A new policy that represents the conditional OR of this policy and the alternative.

Operators

operator !(AsyncPolicyBase<TModel, TMetadata>)

Negates a policy.

public static AsyncPolicyBase<TModel, TMetadata> operator !(AsyncPolicyBase<TModel, TMetadata> policy)

Parameters

policy AsyncPolicyBase<TModel, TMetadata>

The policy to negate.

Returns

AsyncPolicyBase<TModel, TMetadata>

A new policy that represents the logical NOT of the policy.