cryogen-core/src/cryogen_core/watcher.clj

22 lines
537 B
Clojure
Raw Normal View History

2014-12-05 15:56:40 +00:00
(ns cryogen-core.watcher
2014-12-04 16:38:48 +00:00
(:require [clojure.java.io :refer [file]]))
(defn get-assets [root]
(file-seq (file root)))
(defn sum-times [path]
(->> (get-assets path) (map #(.lastModified %)) (reduce +)))
(defn watch-assets [root action]
(loop [times (sum-times root)]
(Thread/sleep 300)
(let [new-times (sum-times root)]
(when-not (= times new-times)
(action))
(recur new-times))))
(defn start-watcher! [root action]
(doto (Thread. #(watch-assets root action))
(.setDaemon true)
(.start)))