Comments (16)
Will do later this week. Perhaps looking at the issues of the go lib and/or upgrading it will also help.
from pod-babashka-fswatcher.
@keychera looks good to me!
from pod-babashka-fswatcher.
I'm on windows 10.
bb version v0.7.4-snapshot
from pod-babashka-fswatcher.
hey, is it the same event you're seeing twice? or is one of them chmod and the other edit?
from pod-babashka-fswatcher.
(def w1 (fw/watch "file.clj"
(fn [{:keys [type path] :as _event}]
(let [now (System/currentTimeMillis)]
(prn [:type type :path path :now now])))
{:recursive true
:delay-ms 250}))
[:type :write :path "file.clj" :now 1649072989448]
[:type :write :path "file.clj" :now 1649072989448]
from pod-babashka-fswatcher.
(def count (atom 0))
(def w1 (fw/watch "file.clj"
(fn [{:keys [type path] :as _event}]
(let [now (System/currentTimeMillis)]
(swap! count inc)
(prn [:type type :path path :now now :count @count])))
{:recursive true
:delay-ms 250}))
saving file prints
[:type :write :path "file.clj" :now 1649073215153 :count 1]
[:type :write :path "file.clj" :now 1649073215156 :count 2]
editing and saving again prints
[:type :write :path "file.clj" :now 1649073268285 :count 3]
[:type :write :path "file.clj" :now 1649073268285 :count 4]
from pod-babashka-fswatcher.
I'm connecting to bb --nrepl-server
from emacs over cider.
from pod-babashka-fswatcher.
Could be something specific to the windows apis or the way the editor saves it. I get two events on my linux machine when saving with vim: chmod and write. Could you try something like echo "foo" > the-file
and see if you still have the duplicate events? @borkdude can you try in windows? I dont have a windows machine off hand.
from pod-babashka-fswatcher.
fsnotify/fsnotify#206
I did try deduping but it introduced other strange behavior.
(defn on-change
([f paths]
(on-change f paths {}))
([f paths {:keys [timeout]
:or {timeout 1000}}]
(let [cache (atom {})
watchers (for [path paths]
(fw/watch path
(fn [{:keys [type path] :as _event}]
(let [now (System/currentTimeMillis)]
(when (= type :write)
(when (or (not (contains? @cache path))
(< timeout (- now (@cache path))))
(swap! cache assoc path now)
(f path)))))
{:recursive true
:delay-ms 250}))]
(fn unwatch-all [] (doseq [w watchers]
(fw/unwatch w))))))
from pod-babashka-fswatcher.
I'm not a fan of trying to "hide" a bug of the underlying library. The best you can do if the underlying library is compensate for this in your own app.
There is another filewatcher pod which is built in Rust, which you could try too:
https://github.com/babashka/pod-registry/blob/master/examples/filewatcher.clj
from pod-babashka-fswatcher.
I guess we don't have a windows build for it yet?
from pod-babashka-fswatcher.
🤦 Maybe switch to Github actions for that one then so we can more easily make a matrix
from pod-babashka-fswatcher.
There is another filewatcher pod which is built in Rust, which you could try too:
It doesn't support Windows.
from pod-babashka-fswatcher.
(fw/watch "folder/"
(fn [event] (prn event))
{:recursive true
:delay-ms 2000})
Saving the file with emacs generates 4 messages but echo "text" >> folder/file.txt
generates 2 messages.
{:type :write, :path "folder\\file.txt"}
{:type :write, :path "folder\\file.txt"}
{:type :write, :path "folder\\file.txt"}
{:type :write, :path "folder\\file.txt"}
{:type :write, :path "folder\\file.txt"}
from pod-babashka-fswatcher.
I encountered this problem as well on Windows 10, I tried saving in VSCode and Notepad and both fires the write events twice
but then I did some digging and found a suggestion from user steve-kessel-aero and a Go code from sejongk in this thread:
fsnotify/fsnotify#122
which suggest making a loop that will fire the latest recorded events on a specific time interval
then I tried writing that Go code in Clojure and come up with this code below:
(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/fswatcher "0.0.3")
(require '[pod.babashka.fswatcher :as fw])
(require '[clojure.core.async :refer [go-loop timeout <!]])
(def target "src")
(println "watching" target)
(def latest-event (atom nil))
(fw/watch target (fn [event] (reset! latest-event event))
{:recursive true})
(defn handle [event]
(println "handled this:" event))
(go-loop [time-unit 1]
(<! (timeout 100))
(let [[event _] (reset-vals! latest-event nil)]
(some-> event handle))
(recur (inc time-unit)))
@(promise)
which served for my use case quite well, so I hope this can help
(also I still have little experience with Clojure so any feedback will be greatly appreciated)
from pod-babashka-fswatcher.
I think this is now fixed by #19
from pod-babashka-fswatcher.
Related Issues (10)
- unwatch should be renamed to stop / remove
- Crashes on error message? HOT 12
- Missing Linux aarch64 release HOT 6
- Add aarch64 release binaries HOT 3
- Duplicate events when :recursive true HOT 3
- Rename to pod-babashka-fsnotify HOT 2
- Add test HOT 2
- Decide on LICENSE HOT 4
- Support watching multiple dirs using a single watcher
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pod-babashka-fswatcher.