cool!
generally don't rely on rebinding vars (with def
or defn
) to hold application state - use an atom
or an agent
instead, and note the defonce
which avoids recompilation wiping out your state
Yeah I started off with defonce but it was still causing the "CompilerException java.net.BindException: Address already in use"
exception. I took what you gave me and somewhat changed it but the core is the same.
(defn start! []
(if (nil? @server)
(do
(println "Starting server...")
(reset! server (resource-routes)))
(do
(println "Server already running.")
@server)))
(defn stop! []
(when (:close @server)
(do
(println "Closing server...")
(reset! server ((:close @server))))))
(defn reload! []
(do
(println "Reloading server...")
(stop!)
(start!)))