Fork me on GitHub
#nrepl
<
2022-06-19
>
victorb09:06:58

I have a script that launches a nrepl session, my editor and now I'm trying to automatically start the server defined in my clojure application together with this. My approach is to wait for the .nrepl-port file to be available, and then doing something like echo "(do (require 'my-app.core) (my-app.core/start-server))" | clj -M:nREPL -m nrepl.cmdline --connect --port $(cat .nrepl-port) . The command works in itself, but it seems that not all namespaces are available even when nrepl starts accepting remote connections, so when I run this command, I'm getting different exceptions each time about various namespaces not being available. I added a sleep 5 between checking for the .nrepl-port file and running the command, but this is brittle as sometimes it seems it takes even longer for the namespaces to be available, would depend on the general load of my system when running. So I guess the question is, anyone know of any better approach here? Or even, can I somehow wait for a namespace to be available before running the command? One idea is to have some sort of retry logic in my remote-sent command, so it'll retry for X times before accepting defeat, but maybe there is a better approach out there

victorb09:06:01

I guess another approach could be to embed the nrepl server in my application instead of launching it standalone, and then I can be sure that all the namespaces are available once the nrepl server is running, as it's running after the namespaces have been available