diff --git a/src/hottub/repl.clj b/src/hottub/repl.clj index b793358..f0b9813 100644 --- a/src/hottub/repl.clj +++ b/src/hottub/repl.clj @@ -1,4 +1,5 @@ (ns hottub.repl + (:use hottub.util) (:require (clojure.tools.nrepl [server :as server] [middleware :as middleware]) (clojure.tools.nrepl.middleware pr-values @@ -34,15 +35,8 @@ (server/stop-server @(:server repl)) (reset! (:server repl) nil)) -(defn clear-and-get-evalqueue [repl] - (let [evalqueueatom (:evalqueue repl)] - (loop [evalqueue @evalqueueatom] - (if (compare-and-set! evalqueueatom evalqueue []) - evalqueue - (recur @evalqueueatom))))) - (defn repl-update [repl] - (doseq [f (clear-and-get-evalqueue repl)] + (doseq [f (reset-returning-old! (:evalqueue repl) [])] (try (f) (catch Exception e (println "couldn't eval:" (.getMessage e)))))) \ No newline at end of file diff --git a/src/hottub/util.clj b/src/hottub/util.clj new file mode 100644 index 0000000..ee8afdb --- /dev/null +++ b/src/hottub/util.clj @@ -0,0 +1,7 @@ +(ns hottub.util) + +(defn reset-returning-old! [a newval] + (loop [oldval @a] + (if (compare-and-set! a oldval newval) + oldval + (recur @a))))