Class DeferredBlock<I, O>
- Namespace
- CounterpointCollective.Dataflow
- Assembly
- Dataflow.Composable.dll
A dataflow block that lets you construct and wire up an entire pipeline before the actual underlying block is available.
Use DeferredBlock when the real IPropagatorBlock<TInput, TOutput> requires asynchronous setup before it can be created (e.g. initializing a database connection, loading configuration, performing I/O, warming caches, etc.).
With this block you can:
- Set up all LinkTo(ITargetBlock<O>, DataflowLinkOptions) connections immediately. These links are recorded and only activated once the inner block is created.
- Start building the rest of your pipeline without having to await the initialization task.
- Accept incoming messages during the initialization phase; they are stored and offered to the inner block once it is ready.
- Request completion or fault at any time; the request is applied either immediately (if the inner block already exists) or propagated correctly once initialization finishes.
As soon as the asynchronous factory produces the real block:
- Pending links are created.
- Postponed messages are forwarded.
- Any previously requested completion or fault is propagated.
After the inner block has been created, DeferredBlock behaves exactly as a transparent wrapper around it.
public class DeferredBlock<I, O> : IPropagatorBlock<I, O>, ISourceBlock<O>, ITargetBlock<I>, IDataflowBlock
Type Parameters
IO
- Inheritance
-
DeferredBlock<I, O>
- Implements
-
IPropagatorBlock<I, O>ISourceBlock<O>ITargetBlock<I>
- Inherited Members
- Extension Methods
Constructors
DeferredBlock(Func<CancellationToken, Task<IPropagatorBlock<I, O>>>, CancellationToken)
public DeferredBlock(Func<CancellationToken, Task<IPropagatorBlock<I, O>>> factory, CancellationToken cancellationToken = default)
Parameters
factoryFunc<CancellationToken, Task<IPropagatorBlock<I, O>>>cancellationTokenCancellationToken
DeferredBlock(Task<IPropagatorBlock<I, O>>, CancellationToken)
public DeferredBlock(Task<IPropagatorBlock<I, O>> factory, CancellationToken cancellationToken = default)
Parameters
factoryTask<IPropagatorBlock<I, O>>cancellationTokenCancellationToken