Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(def server-state (atom nil))
(defmulti server-control identity)
(defmethod server-control :start
[& config]
(if @server-state
(println "START: Aborting, already initialized. Use :restart")
(let [handler (:handler config)]
(println "START: Starting server...")
(swap! server-state (fn [_] (start-tcp-server handler {:port 3000})))
(println "START: Startup complete"))))
(defmethod server-control :stop
[& config]
(when @server-state
(do
(println "Shutting down server...")
(@server-state)
(swap! server-state (fn [_] nil))))
(println "Shutdown complete."))
(defmethod server-control :restart
[& config]
(doriath.mini/server-control :stop)
(println "server stopped -- reinitializing")
(use :reload-all 'doriath.mini)
(println "reloaded namespace")
(doriath.mini/server-control :start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.