           fs (.getFileSystem path)
           service (.newWatchService fs)]
       (letfn [(buildf []
-                (let [start (System/nanoTime)]
-                  (build source opts compiler-env)
-                  (println "... done. Elapsed"
-                    (/ (unchecked-subtract (System/nanoTime) start) 1e9) "seconds")
-                  (flush)))
+                (try
+                  (let [start (System/nanoTime)]
+                    (build source opts compiler-env)
+                    (println "... done. Elapsed"
+                      (/ (unchecked-subtract (System/nanoTime) start) 1e9) "seconds")
+                    (flush))
+                  (when-let [f (:watch-fn opts)]
+                    (f))
+                  (catch Throwable e
+                    (.printStackTrace e))))
               (watch-all [^Path root]
                 (Files/walkFileTree root
                   (reify

     :output-dir "samples/hello/out"
     :cache-analysis true
     :source-map true
     :verbose true})
  )

;; =============================================================================

(defn watch
  "Given a source directory, produce runnable JavaScript. Watch the source
   directory for changes rebuliding when necessary. Takes the same arguments as
   cljs.closure/build in addition to :watch-fn, a function of no arguments to
   run after a successful build."
  ([source opts]
    (watch source opts
      (if-not (nil? env/*compiler*)
