run static method
- void action()
Runs action inside a batch: writes to any Observable or reactive
collection during action are coalesced so every distinct changed
observable notifies its listeners exactly once, after action
returns. Nested calls are supported — only the outermost call flushes.
If action throws, the depth counter is still restored (via
finally); the pending queue built up so far is discarded without
notifying anyone. This is a deliberate, documented choice: a batch
that fails partway through is treated as not having completed, so
listeners never observe an inconsistent partial update.
Executa action dentro de um batch: escritas em qualquer Observable
ou coleção reativa durante action são agrupadas, de forma que cada
observável distinto alterado notifique seus listeners exatamente uma
vez, após action retornar. Chamadas aninhadas são suportadas —
apenas a chamada mais externa libera o flush.
Se action lançar uma exceção, o contador de profundidade ainda é
restaurado (via finally); a fila pendente construída até então é
descartada sem notificar ninguém. Esta é uma escolha deliberada e
documentada: um batch que falha no meio do caminho é tratado como não
tendo sido concluído, então os listeners nunca observam uma
atualização parcial inconsistente.
Implementation
static void run(void Function() action) {
_depth++;
try {
action();
} catch (_) {
if (_depth == 1) {
for (final ListenerRegistry registry in _pending) {
registry.markEngineStaleWithoutNotifyingListeners();
}
_pending.clear();
_dirtyFlushCallbacks.clear();
}
rethrow;
} finally {
_depth--;
if (_depth == 0) {
_flushPending();
}
}
}