Class AsyncDecorator<TIn, TOut>
- Namespace
- PatternKit.Structural.Decorator
- Assembly
- PatternKit.Core.dll
Fluent, allocation-light async decorator that wraps a component and applies layered enhancements. Build once, then call ExecuteAsync(TIn, CancellationToken) to run the component through the decorator pipeline.
public sealed class AsyncDecorator<TIn, TOut>
Type Parameters
TInInput type passed to the component.
TOutOutput type produced by the component.
- Inheritance
-
AsyncDecorator<TIn, TOut>
- Inherited Members
Examples
var decorator = AsyncDecorator<int, int>.Create(async (x, ct) => await ComputeAsync(x, ct))
.Before(async (x, ct) => x + 1)
.After(async (input, result, ct) => result * 10)
.Build();
var result = await decorator.ExecuteAsync(5);
Remarks
Mental model: A base async component is wrapped by zero or more async decorators.
Immutability: After Build(), the decorator chain is immutable and safe for concurrent reuse.
Methods
Create(Component)
Creates a new builder for constructing an async decorated component.
public static AsyncDecorator<TIn, TOut>.Builder Create(AsyncDecorator<TIn, TOut>.Component component)
Parameters
componentAsyncDecorator<TIn, TOut>.Component
Returns
- AsyncDecorator<TIn, TOut>.Builder
ExecuteAsync(TIn, CancellationToken)
Executes the decorated component asynchronously.
public ValueTask<TOut> ExecuteAsync(TIn input, CancellationToken ct = default)
Parameters
inputTInctCancellationToken
Returns
- ValueTask<TOut>