-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Story
I have a scenario where I'm watching a directory for one specific file (to be added/changed/deleted). However this file is in a directory with many subdirectories and nested files. Calling beholder/watch on this dir takes about 1500 milliseconds on my machine. I did some experimentation by adding a custom visitor to the DirectorWatcher and I was able to bring this down to 5 milliseconds. Maybe this is interesting to add to beholder as an option.
Possible implementation
The DirectoryWatcher.Builder class allows to add a custom visitor option. This is currently not supported by beholder, but it could be added quite simple (see below). However the create would have to be made public or it would have to be forwarded via one of the watch functions, so API design is the hardest part here.
Below would be a possible implementation. Here is also a gist of how to create a visitor that can be used here.
(defn create
"Creates a watcher taking a callback function `cb` that will be invoked
whenever a file in one of the `paths` chages.
Not meant to be called directly but use `watch` or `watch-blocking` instead."
[cb paths & {:keys [^FileTreeVisitor visitor]}]
(-> (cond-> (DirectoryWatcher/builder)
visitor
(.fileTreeVisitor visitor))
(.paths (map to-path paths))
(.listener (fn->listener cb))
(.build)))