batch<T> static method

T batch<T>(
  1. T action()
)

Runs action while coalescing synchronous ListNotifier notifications.

Each mutated notifier inside action is queued at most once and its listeners are notified when the outermost batch completes.

Implementation

static T batch<T>(T Function() action) {
  _batchDepth++;
  try {
    return action();
  } finally {
    _batchDepth--;
    if (_batchDepth == 0 &&
        (_batchedNotifiers.isNotEmpty || _batchedComputed.isNotEmpty)) {
      _flushBatch();
    }
  }
}