notify
notify copied to clipboard
[Feature Request]: provider a watch multiple files api to instead of multiple call `Watcher#watch`
System details
- OS/Platform name and version: MacOS 14.4.1 (M3 pro)
- Rust version (if building from source):
rustc --version: rustc 1.77.2 - Notify version (or commit hash if building from git): 7.0.0
- If you're coming from a project that makes use of Notify, what it is, and a link to the downstream issue if there is one:
- Filesystem type and options:
- On Linux: Kernel version:
- On Windows: version and if you're running under Windows, Cygwin (unsupported), Linux Subsystem:
- If you're running as a privileged user (root, System):
- If you're running in a container, details on the runtime and overlay:
- If you're running in a VM, details on the hypervisor:
What you did (as detailed as you can)
The performance has more overhead if multiple call Watcher#watch, watching 158 files take 88 ms at my local. The overhead look like the FsEventWatcher#stop and FsEventWatcher#run is call multiple times. It could be improve like this.
fn watch_multiple(&mut self, path: Vec<&Path>, recursive_mode: RecursiveMode) -> Result<()> {
self.stop();
for path in path {
let result = self.append_path(path, recursive_mode);
}
// ignore return error: may be empty path list
let _ = self.run();
result
}
The Watcher#unwatch API is also need to give similar API.
If here provide a API to do it, it could be nice. Thank you.
+1
+1, I also just noticed this.
Some thoughts on a potential implementation:
watchis a trait method. Taking the paths to watch asimpl IntoIteratorwould make the trait not object-safe.watch_manycould get aSelf: Sizedbound.watch_manycould take the paths as a slice.watch_manycould take the paths as a trait object iterator.
- How should error handling work?
- Could return on first error, but the caller wouldn't know which path failed.
- Could return a
Vec<Result>, with one entry for each path to be added. - Could use a custom error type, that includes information about which path(s) failed.
- Could do something fancy with closures, to support calling as
watcher.watch_many(|add| { for p in my_paths { add(p)? } }- This has the same object-safety concerns as above.