You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
(defncreate"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)))
The text was updated successfully, but these errors were encountered:
FYI, I had expected that adding a visitor with :max-depth 1 would not give notifications for nested directories, but that doesn't seem to be the case. However it does load much faster for directories with many subdirectories. So I'm not sure what's happening behind the scenes exactly.
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 customvisitor
to theDirectorWatcher
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 thecreate
would have to be made public or it would have to be forwarded via one of thewatch
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.
The text was updated successfully, but these errors were encountered: