(defn watch! [opts & groups]
(let [[opts
groups] (if (map? opts) [opts groups] [{} (cons opts groups)])
watcher (-> opts new-watcher)
specs (mapcat
(fn [specs]
(let [a (agent {})]
(map (fn [spec]
(-> spec
extract-paths-by-type
process-paths
process-context
(update-in [:context] #(partial send-off a %))
process-handler
(update-in [:handler] #(partial send-off a %))))
specs)))
groups)
paths (-> (mapcat :paths specs)
remove-duplicate-paths
remove-children-paths)
handler* (apply juxt (map :handler specs))
context* (apply juxt (map :context specs))]
(context*)
(doseq [path paths]
(watcher/register! watcher path [:create :modify :delete]))
{:thread (doto
(Thread.
(fn []
(when-not
(empty?
(mapv handler* (watcher/take! watcher)))
(recur))))
.start)
:watcher watcher}))