watchForFileChanges method

void watchForFileChanges()

Implementation

void watchForFileChanges() {
  logger.detail('Watching ${root.path} for changes');

  _watcherSubscription ??= DirectoryWatcher(root.path)
      .events
      .asyncMap(shouldReload)
      .where((event) => event.$1)
      .debounce(Duration.zero)
      .listen((event) => _reload(event.$2));

  _watcherSubscription?.asFuture<void>().then((_) async {
    await _cancelWatcherSubscription();
    await stop();
  }).catchError((_) async {
    await _cancelWatcherSubscription();
    await stop(1);
  }).ignore();
}