Expand description
Lazy computed values that auto-update from Observable dependencies.
§Design
Computed<T> wraps a compute function and its cached result in shared,
reference-counted storage. When any dependency changes, the cached value is
invalidated (marked dirty). The next call to get()
recomputes and caches the result.
§Invariants
get()always returns a value consistent with the current state of all dependencies (no stale reads after a dependency mutation completes).- The compute function is called at most once per dependency change cycle (memoization).
- If no dependency has changed,
get()returns the cached value in O(1). - Version increments by exactly 1 per recomputation.
§Failure Modes
- Compute function panics: The cached value remains from the last
successful computation. The dirty flag stays set so the next
get()will retry. - Dependency dropped: If the source
Observableis dropped, the subscription becomes inert. The computed value retains its last cached result and never becomes dirty again from that source.
Structs§
- Computed
- A lazily-evaluated, memoized value derived from one or more
Observabledependencies.