Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkgs/watcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 1.1.5-wip

- `DirectoryWatcher` on Windows watches in a separate Isolate to make buffer
exhaustion, "Directory watcher closed unexpectedly", much less likely. The old
implementation which does not use a separate Isolate is available as
`DirectoryWatcher(path, runInIsolateOnWindows: false)`.
- Polling watchers now check file sizes as well as "last modified" times, so
they are less likely to miss changes on platforms with low resolution
timestamps.
Expand Down
13 changes: 11 additions & 2 deletions pkgs/watcher/lib/src/directory_watcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import 'directory_watcher/windows.dart';
/// the message "Directory watcher closed unexpectedly" on the event stream. The
/// code using the watcher needs to do additional work to account for the
/// dropped events, for example by recomputing interesting files from scratch.
/// By default, the watcher is started in a separate isolate to make this less
/// likely. Pass `runInIsolateOnWindows = false` to not launch an isolate.
abstract class DirectoryWatcher implements Watcher {
/// The directory whose contents are being monitored.
@Deprecated('Expires in 1.0.0. Use DirectoryWatcher.path instead.')
Expand All @@ -35,7 +37,11 @@ abstract class DirectoryWatcher implements Watcher {
/// shorter will give more immediate feedback at the expense of doing more IO
/// and higher CPU usage. Defaults to one second. Ignored for non-polling
/// watchers.
factory DirectoryWatcher(String directory, {Duration? pollingDelay}) {
///
/// On Windows, pass [runInIsolateOnWindows] `false` to not run the watcher
/// in a separate isolate to reduce buffer exhaustion failures.
factory DirectoryWatcher(String directory,
{Duration? pollingDelay, bool runInIsolateOnWindows = true}) {
if (FileSystemEntity.isWatchSupported) {
var customWatcher = createCustomDirectoryWatcher(
directory,
Expand All @@ -44,7 +50,10 @@ abstract class DirectoryWatcher implements Watcher {
if (customWatcher != null) return customWatcher;
if (Platform.isLinux) return LinuxDirectoryWatcher(directory);
if (Platform.isMacOS) return MacOSDirectoryWatcher(directory);
if (Platform.isWindows) return WindowsDirectoryWatcher(directory);
if (Platform.isWindows) {
return WindowsDirectoryWatcher(directory,
runInIsolate: runInIsolateOnWindows);
}
}
return PollingDirectoryWatcher(directory, pollingDelay: pollingDelay);
}
Expand Down
Loading
Loading