Skip to main content

batch

Function batch 

Source
pub fn batch<R>(writes: impl FnOnce() -> R) -> R
Expand description

Run writes and notify each changed Signal once when it returns, instead of after every write.

Values and versions update immediately, so reads inside the batch see the new state. Notifications are deferred only for writes made on the calling thread; other threads are unaffected. Nested batches flush when the outermost one ends. Each deferred notification carries the signal’s latest version, and is delivered even if writes panics, because the values have already changed.

ⓘ
std::thread::spawn(move || {
    let rows = load_rows();
    sui_reactive::batch(|| {
        rows_signal.set(rows);
        status.set(Status::Loaded);
        selection.set(None);
    }); // observers of each signal run once, here, on this thread
});