Skip to content

Compute Services: Diagrams

Text-based diagrams for the core concepts introduced in Part 01.

Computed<T> Lifecycle States

Capturing Computed<T> Values

CallReturns
await counters.Get('a')int (value only)
await Computed.Capture(() => counters.Get('a'))Computed<int>

Computed<T> API:

Property/MethodReturns
.Valueint
.IsConsistent()bool
.Invalidate()void
.Update()Task<Computed<T>>
.WhenInvalidated()Task
.When(predicate)Task<Computed<T>>
.Changes()IAsyncEnumerable
.Invalidatedevent

Invalidation Block Behavior

csharp
using (Invalidation.Begin()) {
    _ = Get(key);  // Does NOT execute method body
}
BehaviorDescription
Method bodyDoes NOT execute
Return valueTask.FromResult(default(T)) or default(T)
Side effectInvalidates cached Computed<T> for this call

Computed Value Dependency Graph (DAG)

Example from PartF: Sum("a", "b") depends on Get("a") and Get("b").

Cascading Invalidation Flow

Compute Method Cache Resolution

State<T> Inheritance Hierarchy

ComputedState<T> Update Loop

MutableState<T> vs ComputedState<T>

MutableState<T>ComputedState<T>
Use case: UI input state (e.g., search box text)Use case: Derived/reactive values (e.g., filtered list, totals)