CngxAsyncRegistry
projects/common/data/async-registry/async-registry.ts
Import#
import { CngxAsyncRegistry } from '@cngx/common/data'
Description#
Opt-in aggregation registry for in-flight async operations.
A single derived source for "is anything loading?" across a whole app: the
shell binds one isAnythingLoading() instead of N hand-maintained flags.
Producers register their CngxAsyncState (via injectAsyncState({ register: true }), the HTTP interceptor, or directly) and unregister on teardown.
Not providedIn: 'root' - consumers opt in with provideAsyncRegistry.
When the registry is absent, producers skip registration entirely.
Keyed by a per-operation uid, not the human label. Async operations are
transient and collide on label; uid identity keeps N concurrent same-label
(or unlabeled) operations independent, so one unregister evicts exactly
its own entry. This is the one deliberate divergence from CngxErrorRegistry
(which keys by a stable scope name).
Both views are computed() only - no effect, no service calls. Inner
status reactivity flows through each entry's CngxAsyncState signals; the
Map signal's mapKeySetEqual short-circuits register/unregister churn
without hiding status changes.
Index#
Methods
Derived State
Methods#
register(state: CngxAsyncState<unknown>, label?: string)Registers an async state under a fresh per-operation uid and returns it.
The optional label is display metadata only - never the map key, so
concurrent same-label (or unlabeled) operations stay independent.