batch method

void batch(
  1. void run()
)

Synchronous batch boundary. Cell updates queue invalidation roots; at batch exit, queued roots trigger propagation. Async slots are marked stale (their next getAsync respawns) but do not execute inside the batch callback — async reruns fire after the batch returns.

Implementation

void batch(void Function() run) {
  final wasBatching = _batching;
  _batching = true;
  try {
    run();
  } finally {
    _batching = wasBatching;
    if (!_batching) {
      // Propagate every queued source and explicit computed root in one
      // frontier walk at the outermost boundary.
      final roots = <Object>[..._batchQueue];
      final cleared = Set<AsyncSlotHandle<dynamic>>.of(_batchClearSlots);
      for (final slot in cleared) {
        slot._onInvalidate();
        roots.add(slot);
      }
      _batchQueue.clear();
      _batchClearSlots.clear();
      _invalidateFrontier(
        roots,
        alreadyInvalidated: cleared,
      );
    }
  }
}