Skip to content

Batched Updates

Reference1 min read
Edit page

On pull-based adapters (GPUI, Xilem) every signal mutation calls request_update(). When a handler mutates several signals in a row this produces redundant re-render requests. Batching suppresses those intermediate notifications and issues a single update when the batch ends.

Import: use quoin_core::prelude::*; (the module) or use quoin_core::batch;

Item Signature Description
batch::with pub fn with<C, R>(cx: &C, f: impl FnOnce() -> R) -> R where C: ReactiveContext Runs f inside a batch scope and then requests a single UI update on cx.
BatchGuard pub struct BatchGuard RAII guard that increments the batch depth on creation and decrements it on drop. Create with BatchGuard::enter().
in_batch pub fn in_batch() -> bool Returns true while inside a with scope.
should_notify pub fn should_notify() -> bool Used by adapter signal implementations: true when a mutation should notify (i.e. no batch is active).

ReactiveContextExt::batch offers the same behavior as a method on the context: cx.batch(\|\| …).

A thread-local depth counter tracks nested batches. The signal implementations of the pull-based adapters consult should_notify() before invoking the update notifier. Fine-grained frameworks (Leptos, Dioxus, Floem) batch internally and ignore this mechanism, so the helper is safe to call everywhere.

let a = cx.create_signal(0u32);
let b = cx.create_signal(0u32);
quoin_core::batch::with(&cx, || {
a.set(1);
b.set(2);
});
assert_eq!((a.get(), b.get()), (1, 2));
// One re-render request instead of two.