Future _processFile()

in lib/src/directory_watcher/polling.dart [141:171]


  Future<void> _processFile(String? file) async {
    // `null` is the sentinel which means the directory listing is complete.
    if (file == null) {
      await _completePoll();
      return;
    }

    final modified = await modificationTime(file);

    if (_events.isClosed) return;

    var lastModified = _lastModifieds[file];

    // If its modification time hasn't changed, assume the file is unchanged.
    if (lastModified != null && lastModified == modified) {
      // The file is still here.
      _polledFiles.add(file);
      return;
    }

    if (_events.isClosed) return;

    _lastModifieds[file] = modified;
    _polledFiles.add(file);

    // Only notify if we're ready to emit events.
    if (!isReady) return;

    var type = lastModified == null ? ChangeType.ADD : ChangeType.MODIFY;
    _events.add(WatchEvent(type, file));
  }