nextjournal / beholder Goto Github PK
View Code? Open in Web Editor NEWThe Clojure directory watcher from Krell as a standalone library.
License: Eclipse Public License 1.0
The Clojure directory watcher from Krell as a standalone library.
License: Eclipse Public License 1.0
The LICENSE file is EPL but the README says
Distributed under the MIT License.
The following error is found on Ubuntu 20
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
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.
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)))
NOTE: this is the case on my Apple Silicon Mac using Java 18.
No :type :delete
events are emitted for any of the files deleted, unless you first create the file after starting the watcher process and then delete it. Files deleted that were created before invoking the watcher do not emit any events.
The types :create
and :update
do not seem to suffer from the same issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.