emit method

void emit(
  1. A a
)

Sends a message to all watchers.

Implementation

void emit(A a) {
  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(a);
    }
  } finally {
    _depth -= 1;

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