Fixes for review comments.
diff --git a/pkgs/watcher/lib/src/directory_watcher/mac_os.dart b/pkgs/watcher/lib/src/directory_watcher/mac_os.dart index e44b7f5..7dc6e7c 100644 --- a/pkgs/watcher/lib/src/directory_watcher/mac_os.dart +++ b/pkgs/watcher/lib/src/directory_watcher/mac_os.dart
@@ -144,18 +144,20 @@ if (_files.containsDir(path)) continue; - late StreamSubscription<FileSystemEntity> subscription; - subscription = Directory(path).list(recursive: true).listen((entity) { + var stream = Directory(path).list(recursive: true); + var subscription = stream.listen((entity) { if (entity is Directory) return; if (_files.contains(path)) return; _emitEvent(ChangeType.ADD, entity.path); _files.add(entity.path); - }, onError: (Object e, StackTrace stackTrace) { - _emitError(e, stackTrace); - }, onDone: () { - _listSubscriptions.remove(subscription); }, cancelOnError: true); + subscription.onDone(() { + _listSubscriptions.remove(subscription); + }); + subscription.onError((Object e, StackTrace stackTrace) { + _emitError(e, stackTrace); + }); _listSubscriptions.add(subscription); } else if (event is FileSystemModifyEvent) { assert(!event.isDirectory);
diff --git a/pkgs/watcher/lib/src/directory_watcher/polling.dart b/pkgs/watcher/lib/src/directory_watcher/polling.dart index 968c9c6..6baa49d 100644 --- a/pkgs/watcher/lib/src/directory_watcher/polling.dart +++ b/pkgs/watcher/lib/src/directory_watcher/polling.dart
@@ -70,7 +70,7 @@ /// queue exists to let each of those proceed at their own rate. The lister /// will enqueue files as quickly as it can. Meanwhile, files are dequeued /// and processed sequentially. - late AsyncQueue<String?> _filesToProcess; + late final AsyncQueue<String?> _filesToProcess; /// The set of files that have been seen in the current directory listing. ///
diff --git a/pkgs/watcher/lib/src/directory_watcher/windows.dart b/pkgs/watcher/lib/src/directory_watcher/windows.dart index 7640373..a8200ee 100644 --- a/pkgs/watcher/lib/src/directory_watcher/windows.dart +++ b/pkgs/watcher/lib/src/directory_watcher/windows.dart
@@ -184,19 +184,20 @@ if (_files.containsDir(path)) continue; var stream = Directory(path).list(recursive: true); - late StreamSubscription<FileSystemEntity> subscription; - subscription = stream.listen((entity) { + var subscription = stream.listen((entity) { if (entity is Directory) return; if (_files.contains(path)) return; _emitEvent(ChangeType.ADD, entity.path); _files.add(entity.path); - }, onDone: () { + }, cancelOnError: true); + subscription.onDone(() { _listSubscriptions.remove(subscription); - }, onError: (Object e, StackTrace stackTrace) { + }); + subscription.onError((Object e, StackTrace stackTrace) { _listSubscriptions.remove(subscription); _emitError(e, stackTrace); - }, cancelOnError: true); + }); _listSubscriptions.add(subscription); } else if (event is FileSystemModifyEvent) { if (!event.isDirectory) {
diff --git a/pkgs/watcher/lib/src/file_watcher/polling.dart b/pkgs/watcher/lib/src/file_watcher/polling.dart index b208a4b..9b9ac5b 100644 --- a/pkgs/watcher/lib/src/file_watcher/polling.dart +++ b/pkgs/watcher/lib/src/file_watcher/polling.dart
@@ -37,7 +37,7 @@ final _readyCompleter = Completer(); /// The timer that controls polling. - late Timer _timer; + late final Timer _timer; /// The previous modification time of the file. ///