emit method

void emit()

Send an empty message to all watchers.

Implementation

void emit() {
  final watchers = _watchers;
  if (watchers == null || watchers.isEmpty) return;

  _depth += 1;
  final end = watchers.length;

  try {
    for (var i = 0; i < end; i += 1) {
      watchers[i]?.call();
    }
  } finally {
    _depth -= 1;

    if (_depth == 0 && _dirty) {
      _dirty = false;
      watchers.removeWhere((fn) => fn == null);
    }
  }
}