in lib/src/directory_watcher/polling.dart [103:137]
void _poll() {
_filesToProcess.clear();
_polledFiles.clear();
void endListing() {
assert(!_events.isClosed);
_listSubscription = null;
// Null tells the queue consumer that we're done listing.
_filesToProcess.add(null);
}
var stream = Directory(path).list(recursive: true);
_listSubscription = stream.listen((entity) {
assert(!_events.isClosed);
if (entity is! File) return;
_filesToProcess.add(entity.path);
}, onError: (Object error, StackTrace stackTrace) {
// Guarantee that ready always completes.
if (!isReady) {
_readyCompleter.complete();
}
if (!isDirectoryNotFoundException(error)) {
// It's some unknown error. Pipe it over to the event stream so the
// user can see it.
_events.addError(error, stackTrace);
}
// When an error occurs, we end the listing normally, which has the
// desired effect of marking all files that were in the directory as
// being removed.
endListing();
}, onDone: endListing, cancelOnError: true);
}