Class ShieldTaskExtensions

Namespace
Kevlar
Assembly
Kevlar.dll

Task-based execution overloads. Most application code returns Task<TResult> rather than ValueTask<TResult>; these overloads let such delegates flow straight into a shield: shield.ExecuteAsync(ct => LoadUserAsync(id, ct)).

public static class ShieldTaskExtensions
Inheritance
ShieldTaskExtensions
Inherited Members

Remarks

They are extension methods deliberately: the instance ValueTask overloads always win overload resolution when both apply (async lambdas), so these only kick in for delegates that genuinely return Task — with no ambiguity and no behavior change elsewhere.

Methods

ExecuteAsync(Shield, Func<CancellationToken, Task>, CancellationToken)

Executes the Task-returning void delegate through the pipeline.

public static ValueTask ExecuteAsync(this Shield shield, Func<CancellationToken, Task> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
action Func<CancellationToken, Task>
cancellationToken CancellationToken

Returns

ValueTask

ExecuteAsync<T>(Shield, Func<CancellationToken, Task<T>>, CancellationToken)

Executes the Task<TResult>-returning delegate through the pipeline.

public static ValueTask<T> ExecuteAsync<T>(this Shield shield, Func<CancellationToken, Task<T>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
action Func<CancellationToken, Task<T>>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExecuteAsync<TState>(Shield, TState, Func<TState, CancellationToken, Task>, CancellationToken)

Executes the Task-returning void delegate through the pipeline, threading state to avoid closure allocations.

public static ValueTask ExecuteAsync<TState>(this Shield shield, TState state, Func<TState, CancellationToken, Task> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
state TState
action Func<TState, CancellationToken, Task>
cancellationToken CancellationToken

Returns

ValueTask

Type Parameters

TState

ExecuteAsync<TResult>(Shield<TResult>, Func<CancellationToken, Task<TResult>>, CancellationToken)

Executes the Task<TResult>-returning delegate through the pipeline.

public static ValueTask<TResult> ExecuteAsync<TResult>(this Shield<TResult> shield, Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield<TResult>
action Func<CancellationToken, Task<TResult>>
cancellationToken CancellationToken

Returns

ValueTask<TResult>

Type Parameters

TResult

ExecuteAsync<T, TState>(Shield, TState, Func<TState, CancellationToken, Task<T>>, CancellationToken)

Executes the Task<TResult>-returning delegate through the pipeline, threading state to avoid closure allocations.

public static ValueTask<T> ExecuteAsync<T, TState>(this Shield shield, TState state, Func<TState, CancellationToken, Task<T>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
state TState
action Func<TState, CancellationToken, Task<T>>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T
TState

ExecuteAsync<TResult, TState>(Shield<TResult>, TState, Func<TState, CancellationToken, Task<TResult>>, CancellationToken)

Executes the Task<TResult>-returning delegate through the pipeline, threading state to avoid closure allocations.

public static ValueTask<TResult> ExecuteAsync<TResult, TState>(this Shield<TResult> shield, TState state, Func<TState, CancellationToken, Task<TResult>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield<TResult>
state TState
action Func<TState, CancellationToken, Task<TResult>>
cancellationToken CancellationToken

Returns

ValueTask<TResult>

Type Parameters

TResult
TState

ExecuteOutcomeAsync(Shield, Func<CancellationToken, Task>, CancellationToken)

Executes a Task-returning void delegate and returns its outcome.

public static ValueTask<Outcome> ExecuteOutcomeAsync(this Shield shield, Func<CancellationToken, Task> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
action Func<CancellationToken, Task>
cancellationToken CancellationToken

Returns

ValueTask<Outcome>

ExecuteOutcomeAsync<T>(Shield, Func<CancellationToken, Task<T>>, CancellationToken)

Executes the Task<TResult>-returning delegate through the pipeline and returns the outcome instead of throwing.

public static ValueTask<Outcome<T>> ExecuteOutcomeAsync<T>(this Shield shield, Func<CancellationToken, Task<T>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
action Func<CancellationToken, Task<T>>
cancellationToken CancellationToken

Returns

ValueTask<Outcome<T>>

Type Parameters

T

ExecuteOutcomeAsync<TState>(Shield, TState, Func<TState, CancellationToken, Task>, CancellationToken)

Executes a Task-returning void delegate, threading state to avoid closure allocations, and returns its outcome.

public static ValueTask<Outcome> ExecuteOutcomeAsync<TState>(this Shield shield, TState state, Func<TState, CancellationToken, Task> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
state TState
action Func<TState, CancellationToken, Task>
cancellationToken CancellationToken

Returns

ValueTask<Outcome>

Type Parameters

TState

ExecuteOutcomeAsync<TResult>(Shield<TResult>, Func<CancellationToken, Task<TResult>>, CancellationToken)

Executes the Task<TResult>-returning delegate through the pipeline and returns the outcome instead of throwing.

public static ValueTask<Outcome<TResult>> ExecuteOutcomeAsync<TResult>(this Shield<TResult> shield, Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield<TResult>
action Func<CancellationToken, Task<TResult>>
cancellationToken CancellationToken

Returns

ValueTask<Outcome<TResult>>

Type Parameters

TResult

ExecuteOutcomeAsync<T, TState>(Shield, TState, Func<TState, CancellationToken, Task<T>>, CancellationToken)

Executes the Task<TResult>-returning delegate through the pipeline, threading state to avoid closure allocations, and returns the outcome instead of throwing.

public static ValueTask<Outcome<T>> ExecuteOutcomeAsync<T, TState>(this Shield shield, TState state, Func<TState, CancellationToken, Task<T>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
state TState
action Func<TState, CancellationToken, Task<T>>
cancellationToken CancellationToken

Returns

ValueTask<Outcome<T>>

Type Parameters

T
TState

ExecuteOutcomeAsync<TResult, TState>(Shield<TResult>, TState, Func<TState, CancellationToken, Task<TResult>>, CancellationToken)

Executes the Task<TResult>-returning delegate through the pipeline, threading state to avoid closure allocations, and returns the outcome instead of throwing.

public static ValueTask<Outcome<TResult>> ExecuteOutcomeAsync<TResult, TState>(this Shield<TResult> shield, TState state, Func<TState, CancellationToken, Task<TResult>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield<TResult>
state TState
action Func<TState, CancellationToken, Task<TResult>>
cancellationToken CancellationToken

Returns

ValueTask<Outcome<TResult>>

Type Parameters

TResult
TState

ExecuteWithContextAsync(Shield, KevlarContext, Func<KevlarContext, Task>)

Executes a context-aware Task delegate using state inherited from parentContext.

public static ValueTask ExecuteWithContextAsync(this Shield shield, KevlarContext parentContext, Func<KevlarContext, Task> action)

Parameters

shield Shield
parentContext KevlarContext
action Func<KevlarContext, Task>

Returns

ValueTask

ExecuteWithContextAsync(Shield, Func<KevlarContext, Task>, CancellationToken)

Executes a context-aware Task-returning void delegate without seeding execution properties. The context is pooled; never retain it beyond the delegate.

public static ValueTask ExecuteWithContextAsync(this Shield shield, Func<KevlarContext, Task> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
action Func<KevlarContext, Task>
cancellationToken CancellationToken

Returns

ValueTask

ExecuteWithContextAsync<T>(Shield, KevlarContext, Func<KevlarContext, Task<T>>)

Executes a context-aware Task<TResult> delegate using state inherited from parentContext.

public static ValueTask<T> ExecuteWithContextAsync<T>(this Shield shield, KevlarContext parentContext, Func<KevlarContext, Task<T>> action)

Parameters

shield Shield
parentContext KevlarContext
action Func<KevlarContext, Task<T>>

Returns

ValueTask<T>

Type Parameters

T

ExecuteWithContextAsync<TState>(Shield, KevlarContext, TState, Func<TState, KevlarContext, Task>)

Executes a context-aware Task delegate using state inherited from parentContext, threading state to avoid closure allocations.

public static ValueTask ExecuteWithContextAsync<TState>(this Shield shield, KevlarContext parentContext, TState state, Func<TState, KevlarContext, Task> action)

Parameters

shield Shield
parentContext KevlarContext
state TState
action Func<TState, KevlarContext, Task>

Returns

ValueTask

Type Parameters

TState

ExecuteWithContextAsync<T>(Shield, Func<KevlarContext, Task<T>>, CancellationToken)

Executes a context-aware Task<TResult>-returning delegate without seeding execution properties. The context is pooled; never retain it beyond the delegate.

public static ValueTask<T> ExecuteWithContextAsync<T>(this Shield shield, Func<KevlarContext, Task<T>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
action Func<KevlarContext, Task<T>>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExecuteWithContextAsync<TState>(Shield, TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, Task>, Action<TState, KevlarProperties>, CancellationToken)

Initializes execution properties, executes a context-aware Task delegate, then exposes final properties before the pooled context is returned.

public static ValueTask ExecuteWithContextAsync<TState>(this Shield shield, TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, Task> action, Action<TState, KevlarProperties> onCompleted, CancellationToken cancellationToken = default)

Parameters

shield Shield
state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, Task>
onCompleted Action<TState, KevlarProperties>
cancellationToken CancellationToken

Returns

ValueTask

Type Parameters

TState

ExecuteWithContextAsync<TState>(Shield, TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, Task>, CancellationToken)

Initializes execution properties, then executes a context-aware Task-returning void delegate.

public static ValueTask ExecuteWithContextAsync<TState>(this Shield shield, TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, Task> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, Task>
cancellationToken CancellationToken

Returns

ValueTask

Type Parameters

TState

ExecuteWithContextAsync<TResult>(Shield<TResult>, KevlarContext, Func<KevlarContext, Task<TResult>>)

Executes a context-aware Task<TResult> delegate using state inherited from parentContext.

public static ValueTask<TResult> ExecuteWithContextAsync<TResult>(this Shield<TResult> shield, KevlarContext parentContext, Func<KevlarContext, Task<TResult>> action)

Parameters

shield Shield<TResult>
parentContext KevlarContext
action Func<KevlarContext, Task<TResult>>

Returns

ValueTask<TResult>

Type Parameters

TResult

ExecuteWithContextAsync<TResult>(Shield<TResult>, Func<KevlarContext, Task<TResult>>, CancellationToken)

Executes a context-aware Task<TResult>-returning delegate without seeding execution properties. The context is pooled; never retain it beyond the delegate.

public static ValueTask<TResult> ExecuteWithContextAsync<TResult>(this Shield<TResult> shield, Func<KevlarContext, Task<TResult>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield<TResult>
action Func<KevlarContext, Task<TResult>>
cancellationToken CancellationToken

Returns

ValueTask<TResult>

Type Parameters

TResult

ExecuteWithContextAsync<T, TState>(Shield, KevlarContext, TState, Func<TState, KevlarContext, Task<T>>)

Executes a context-aware Task<TResult> delegate using state inherited from parentContext, threading state to avoid closure allocations.

public static ValueTask<T> ExecuteWithContextAsync<T, TState>(this Shield shield, KevlarContext parentContext, TState state, Func<TState, KevlarContext, Task<T>> action)

Parameters

shield Shield
parentContext KevlarContext
state TState
action Func<TState, KevlarContext, Task<T>>

Returns

ValueTask<T>

Type Parameters

T
TState

ExecuteWithContextAsync<T, TState>(Shield, TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, Task<T>>, Action<TState, KevlarProperties>, CancellationToken)

Initializes execution properties, executes a context-aware Task<TResult> delegate, then exposes final properties before the pooled context is returned.

public static ValueTask<T> ExecuteWithContextAsync<T, TState>(this Shield shield, TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, Task<T>> action, Action<TState, KevlarProperties> onCompleted, CancellationToken cancellationToken = default)

Parameters

shield Shield
state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, Task<T>>
onCompleted Action<TState, KevlarProperties>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T
TState

ExecuteWithContextAsync<T, TState>(Shield, TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, Task<T>>, CancellationToken)

Initializes execution properties, then executes a context-aware Task<TResult>-returning delegate.

public static ValueTask<T> ExecuteWithContextAsync<T, TState>(this Shield shield, TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, Task<T>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield
state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, Task<T>>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T
TState

ExecuteWithContextAsync<TResult, TState>(Shield<TResult>, KevlarContext, TState, Func<TState, KevlarContext, Task<TResult>>)

Executes a context-aware Task<TResult> delegate using state inherited from parentContext, threading state to avoid closure allocations.

public static ValueTask<TResult> ExecuteWithContextAsync<TResult, TState>(this Shield<TResult> shield, KevlarContext parentContext, TState state, Func<TState, KevlarContext, Task<TResult>> action)

Parameters

shield Shield<TResult>
parentContext KevlarContext
state TState
action Func<TState, KevlarContext, Task<TResult>>

Returns

ValueTask<TResult>

Type Parameters

TResult
TState

ExecuteWithContextAsync<TResult, TState>(Shield<TResult>, TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, Task<TResult>>, Action<TState, KevlarProperties>, CancellationToken)

Initializes execution properties, executes a context-aware Task<TResult> delegate, then exposes final properties before the pooled context is returned.

public static ValueTask<TResult> ExecuteWithContextAsync<TResult, TState>(this Shield<TResult> shield, TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, Task<TResult>> action, Action<TState, KevlarProperties> onCompleted, CancellationToken cancellationToken = default)

Parameters

shield Shield<TResult>
state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, Task<TResult>>
onCompleted Action<TState, KevlarProperties>
cancellationToken CancellationToken

Returns

ValueTask<TResult>

Type Parameters

TResult
TState

ExecuteWithContextAsync<TResult, TState>(Shield<TResult>, TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, Task<TResult>>, CancellationToken)

Initializes execution properties, then executes a context-aware Task<TResult>-returning delegate.

public static ValueTask<TResult> ExecuteWithContextAsync<TResult, TState>(this Shield<TResult> shield, TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, Task<TResult>> action, CancellationToken cancellationToken = default)

Parameters

shield Shield<TResult>
state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, Task<TResult>>
cancellationToken CancellationToken

Returns

ValueTask<TResult>

Type Parameters

TResult
TState