Expand description
Batch update coalescing for [Observable] notifications.
When multiple Observable values are updated in rapid succession,
subscribers receive a notification for each change. In render-heavy
scenarios this causes redundant intermediate renders. Batch coalescing
defers all notifications until the batch scope exits, then fires each
unique callback at most once.
§Usage
ⓘ
use ftui_runtime::reactive::batch::BatchScope;
let x = Observable::new(0);
let y = Observable::new(0);
{
let _batch = BatchScope::new();
x.set(1); // notification deferred
y.set(2); // notification deferred
x.set(3); // notification deferred (coalesced with first x.set)
} // all notifications fire here, x subscribers called once with value 3§Invariants
- Nested batches are supported: only the outermost scope triggers flush.
- Within a batch,
Observable::get()always returns the latest value (values are updated immediately, only notifications are deferred). - After a batch exits, all subscribers see the final state, never an intermediate state.
- Flush calls deferred callbacks in the order they were first enqueued.
§Failure Modes
- Callback panics during flush: Remaining callbacks are still called. The first panic is re-raised after all callbacks have been attempted.
Structs§
- Batch
Scope - RAII guard that begins a batch scope.
Functions§
- defer_
or_ run - Enqueue a deferred notification to be fired when the current batch exits.
- defer_
or_ run_ keyed - Enqueue a deferred notification keyed by
key. - is_
batching - Returns true if a batch is currently active on this thread.
- record_
rows_ changed - Record row-level changes while a batch is active.