This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-22
Channels
- # beginners (240)
- # boot (23)
- # bristol-clojurians (3)
- # cider (101)
- # cljs-dev (52)
- # cljsrn (17)
- # clojure (212)
- # clojure-dusseldorf (2)
- # clojure-greece (2)
- # clojure-italy (9)
- # clojure-russia (1)
- # clojure-spec (91)
- # clojure-uk (33)
- # clojurescript (164)
- # community-development (23)
- # core-async (24)
- # core-logic (9)
- # cursive (18)
- # datavis (1)
- # datomic (119)
- # emacs (13)
- # events (1)
- # figwheel (2)
- # fulcro (86)
- # graphql (1)
- # immutant (5)
- # jobs-discuss (6)
- # leiningen (19)
- # lumo (46)
- # nyc (7)
- # off-topic (23)
- # parinfer (15)
- # pedestal (3)
- # planck (32)
- # re-frame (48)
- # reagent (75)
- # ring-swagger (13)
- # rum (32)
- # shadow-cljs (402)
- # spacemacs (5)
- # specter (3)
- # tools-deps (11)
- # unrepl (20)
- # vim (135)
- # yada (3)
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!)))