(def java-watcher-impl
{:register! (fn [^WatchService this ^Path path events]
(recursive-register! this path events
#(.register path this %)
#(.reset ^WatchKey %)))
:take! (fn [^WatchService this]
(try
(when-let [^WatchKey watch-key (try
(.take this)
(catch InterruptedException _ _ nil))]
(let [events (->> (.pollEvents watch-key)
(map WatchEvent->watch-event)
(mapcat
(partial handle-watch-event! this (.watchable watch-key))))]
(.reset watch-key)
events))
(catch java.nio.file.ClosedWatchServiceException _ _ nil)))
:stop! (fn [^WatchService this]
(.close this))})