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
TModelThe model type that the policy will evaluate against
TMetadataThe type of the metadata to associate with the predicate
- Inheritance
-
AsyncSpecBase<TModel>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
otherAsyncPolicyBase<TModel, TMetadata>The asynchronous policy to evaluate in the event that
thispolicy is satisfied
Returns
- AsyncPolicyBase<TModel, TMetadata>
A new AsyncPolicyBase<TModel, TMetadata> that will perform the conditional "And" operation between
thisandotherwhen 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
otherPolicyBase<TModel, TMetadata>The synchronous policy to evaluate in the event that
thispolicy 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
modelTModelThe model to evaluate the policy against.
cancellationTokenCancellationTokenA 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
modelTModelThe model to evaluate the policy against.
cancellationTokenCancellationTokenA 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
modelTModelThe model to evaluate the specification against.
cancellationTokenCancellationTokenA 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
alternativeAsyncPolicyBase<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
alternativePolicyBase<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
policyAsyncPolicyBase<TModel, TMetadata>The policy to negate.
Returns
- AsyncPolicyBase<TModel, TMetadata>
A new policy that represents the logical NOT of the policy.