Fork me on GitHub
#component
<
2020-11-23
>
oliver10:11:34

Hi, anyone here using Steven Collins' https://github.com/lomin/component-restart ? I'm using it pretty much the way it apparently is supposed to: (defn -main [& args] (println "Starting the system. With restart watcher.") (let [started (sys/start (system/example-system {}))] (restart/watch (var -main) started))) Once I call (-main) from my CIDER-REPL the system starts and reloading/restarting works pretty much as advertised. My REPL however is stuck in some evaluation, so I cannot evaluate anything inside my buffers. Any idea on how to investigate this?

seancorfield18:11:20

If you call (future (-main)) it should execute on a thread and leave your REPL unblocked.

seancorfield18:11:50

(but then you can't easily stop the background process)

seancorfield18:11:53

My recommendation is always: do not use watchers/reload machinery. Provide a top-level def for the system Component, and then alter-var-root .. component/start / alter-var-root .. component/stop on it manually as needed. Most folks have some convenience functions, sometimes in their user.clj file, that wrap that in simple start / stop functions @services

seancorfield18:11:56

(and if you are careful with function var references, you shouldn't need to restart your component system at all: just start it once and then eval every change you make into the running program)

oliver20:11:50

Why am I not surprised to hear you discourage the use of automatic reloading 😉 … I had actually tried using future (and thread) myself but I tried wrapping just the (restart/watch (var -main) started) part, which didn't work… your solution works better but gives me no more than your second approach would (probably due to some quirk with the template I'm trying to get working here) I have, however, gotten your second approach to work successfully… and it's more than enough. Many thanks for your help on this occasion (and previous ones). Cheers!

3