refactor clear-and-get-evalqueue into the reusable reset-returning-old!
This commit is contained in:
parent
f3f5d007f9
commit
e3d4129d64
|
@ -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))))))
|
7
src/hottub/util.clj
Normal file
7
src/hottub/util.clj
Normal file
|
@ -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))))
|
Loading…
Reference in a new issue