Batcher
Batcher<
K,E,V> =object
Defined in: Core/Batcher.ts:32
A microtask-coalescing request demultiplexer that batches concurrent single-key lookups into a single bulk query to eliminate N+1 query loops.
Unlike traditional cache-bound loaders, Batcher is stateless across execution turns:
once a batch resolves and its callers settle, its pending queue clears. This allows
Batcher instances to live safely as long-lived application singletons without memory
leaks or cross-request stale state.
Example
Section titled “Example”Type Parameters
Section titled “Type Parameters”K
E
V
Properties
Section titled “Properties”
readonlyflush: () =>Deferred<void>
Defined in: Core/Batcher.ts:65
Immediately flushes and settles all currently queued batches without waiting for the microtask tick or window timer to elapse.
Primarily used in unit tests or before transaction boundaries to guarantee deterministic batch execution.
Returns
Section titled “Returns”Deferred<void>
Batcher.load to enqueue individual lookups.
Defined in: Core/Batcher.ts:41
Immediately coalesces the given key into the active batch window and returns
an eager Deferred resolving to a tri-state Batcher.Outcome<E, V, K>.
Parameters
Section titled “Parameters”K
The key to look up.
signal?
Section titled “signal?”AbortSignal
Optional AbortSignal to cancel this individual caller’s lookup.
Returns
Section titled “Returns”Batcher.loadMany to coalesce multiple keys in a single call.
loadMany
Section titled “loadMany”
readonlyloadMany: (keys,signal?) =>Deferred<readonlyOutcome<E,V,K>[]>
Defined in: Core/Batcher.ts:54
Immediately coalesces multiple keys into the batch window and returns their resolved outcomes in order.
Does not short-circuit: preserves discrete per-key outcomes (Ok, Missing, or Err)
for each requested key.
Parameters
Section titled “Parameters”readonly K[]
The collection of keys to look up.
signal?
Section titled “signal?”AbortSignal
Optional AbortSignal to cancel this caller’s lookup batch.
Returns
Section titled “Returns”Deferred<readonly Outcome<E, V, K>[]>
Batcher.load to look up an individual key.