Class InlineProjectionWait
- Namespace
- Excalibur.EventSourcing
- Assembly
- Excalibur.EventSourcing.Abstractions.dll
Suspends the read-your-write wait that an inline projection normally performs on every save, for a bulk writer that will drive the projection cursor itself once at the end of its batch.
public static class InlineProjectionWait
- Inheritance
-
InlineProjectionWait
- Inherited Members
Remarks
The cost this exists to remove. An inline projection advances event by event, because each save waits for the projection cursor to reach the position that save just committed. That is the correct price for a request that writes and then reads its own write. It is the wrong price for a bulk writer — a change-data-capture backfill, an import, a replay — which writes thousands of aggregates and reads none of them back. There the per-save wait is paid in full, serially, and any per-page cost on the projection side becomes a per-event cost: a projection store configured to make each page searchable before its checkpoint advances performs one full index refresh per event, and the refresh becomes the throughput limit for the whole job.
What it does and does not change. Inside the scope, a save still commits its events durably and still returns; only the foreground WAIT is skipped, and the save reports Deferred so a deferred wait can never be mistaken for a confirmed one. The events remain queued for the inline cursor exactly as before. Nothing about durability, ordering or the projection's eventual content changes.
The obligation it transfers to you. Something must still advance the cursor. In a host that runs hosted services the inline background loop does it, so the projection catches up on its own. In a pull-driven host — a function, a worker that runs no hosted services, a console job — nothing does, and the caller MUST drive it: call ProcessPendingAsync(CancellationToken) once after the batch. That single call folds everything the batch committed in pages, so a per-page cost is paid per page rather than per event, which is the whole saving.
Do not wrap a request handler in this. If any code inside the scope reads a projection it expects its own write to appear in, it will not see it. The scope is for a writer that reads nothing back. It is ambient and flows to the work started inside it, so it covers a handler called within the scope without that handler knowing — which is what makes it usable around existing code, and also why its extent should be kept as narrow as the batch.
using (InlineProjectionWait.Suppress())
{
foreach (var record in batch)
{
await handler.ProcessAsync(record, cancellationToken);
}
}
// One fold for the whole batch, in pages, instead of one per record.
var result = await processor.ProcessPendingAsync(cancellationToken);
Modelled on SuppressFlow(): an ambient, scoped, nestable suppression whose disposal restores exactly the state that preceded it.
Properties
IsSuppressed
Gets a value indicating whether the inline read-your-write wait is currently suppressed on this execution context.
public static bool IsSuppressed { get; }
Property Value
- bool
true while at least one Suppress() scope is open on this context; otherwise false.
Methods
Suppress()
Suppresses the inline read-your-write wait until the returned scope is disposed.
public static IDisposable Suppress()
Returns
- IDisposable
A scope that restores the previous suppression state when disposed.
Remarks
Nestable: an inner scope's disposal restores the outer scope rather than clearing suppression, so a batch that calls into code which itself suppresses is not silently un-suppressed partway through. Disposal is idempotent.
The concrete scope type is deliberately not public — the same shape as BeginScope<TState>(TState), whose scope is an opaque IDisposable. A caller has nothing to do with the scope but dispose it, so exposing a named type would add public surface carrying no consumer decision.