component

2017-09-21T18:28:53.000323Z

I'm using component and for some reason, no combination of the following is running my latest changes - component/stop - clojure.tools.namespace.repl/refresh (or (refresh :after ...)) - component/start any idea what's up?

2017-09-21T18:29:46.000261Z

stop followed by refresh followd by start should work

2017-09-21T18:30:00.000314Z

i'm using this that I've found:

(defn go []
  (init)
  (start))

(defn reset []
  (stop)
  (refresh :after 'user/go))

2017-09-21T18:30:13.000122Z

but if you put any exclusive state (like eg. opening an http port) in the component, and called refresh before stop, then you are stuck

2017-09-21T18:30:57.000506Z

because the namespace has been teared down and deconstructed, so you no longer have a convenient handle to the thing monopolizing the resource

donaldball 2017-09-21T18:31:27.000178Z

My usual repl recipe is:

(defn init!
  []
  (log/info :msg "Initializing repl system")
  (let [config (config/load-config)]
    (alter-var-root #'system (constantly (system/assemble-system config)))))

(defn start!
  []
  (when-not (:started? system)
    (log/info :msg "Starting repl system")
    (alter-var-root #'system system/start)))

(defn stop!
  []
  (when (:started? system)
    (log/info :msg "Stopping repl system")
    (alter-var-root #'system system/stop)))

(defn restart!
  []
  (stop!)
  (start!))

(defn rebuild!
  []
  (stop!)
  (init!)
  (start!))

2017-09-21T18:31:46.000304Z

it's weird, manually refreshing after a stop seems to "find" my changed files, at least as far as what gets printed in the repl (cider) but then... it still is running the old code.

2017-09-21T18:32:24.000017Z

and @donaldball that's basically what I have, pretty close to stuart sierra's recipe

donaldball 2017-09-21T18:38:20.000561Z

I dunno, sorry, I don’t really tend to use tools.namespace

2017-09-21T18:41:13.000532Z

@josh.freckleton what if you use load-file or require with the :reload arg, does that change things where refresh does not?

2017-09-21T18:41:29.000347Z

if so, it could be that tools.namespace is confused or misconfigured

danielcompton 2017-09-21T20:39:54.000080Z

@josh.freckleton sometimes I find tools.namespace gets really stuck and I have to call c.t.n.repl/clear to reset things

danielcompton 2017-09-21T20:40:00.000141Z

Also, are you using lein or boot?

2017-09-21T20:59:27.000392Z

@danielcompton I'm on lein, I'll have to look into clear, thanks! It sounds like that's what's going on and I'm not sure why!

danielcompton 2017-09-21T21:14:15.000399Z

also reloaded.repl is great for standardising all of the behaviour above ^^

danielcompton 2017-09-21T21:14:23.000150Z

pretty much the same but nice to have in a library, at least I like it