run method

T run()

Runs the watcher and returns the result.

Implementation

T run() {
  if (_firstRun) {
    _firstRun = false;
  } else {
    _runCleanup();
  }

  final oldWatchers = watchers;
  watchers = {};

  final oldWatcher = setCurrentWatcher(this);
  final output = dryRun();
  restoreCurrentWatcher(oldWatcher);

  if (!setEquals(watchers, oldWatchers)) {
    _listenable?.removeListener(onChange);
    if (watchers.isNotEmpty) {
      _listenable = Listenable.merge(watchers)..addListener(onChange);
    } else {
      _listenable = null;
    }
  } else {
    watchers = oldWatchers;
  }

  // clear computes not used
  for (int i = currentIndexCompute;; i++) {
    final compute = computes[i];
    if (compute == null) break;

    assert(!watchers.contains(compute.compute),
        'Watcher should not be used in computed');

    compute.dispose();
    computes.remove(i);
  }

  currentIndexCompute = 0;
  return output;
}