Fork me on GitHub
#cider
<
2021-01-06
>
solf10:01:03

I want to embed an nrepl server in one of my scripts, but only when enabled via a flag. However just requiring nrepl.server without calling nrepl.server/start-server is enough to prevent the script from exiting immediately. Is this intended? Any workarounds without explicitly quitting at the end of the script?

solf10:01:09

I also tried to call (require ...) inside a function, but it seems it only works when called on top-level?

(ns test
  #_(:require
     [nrepl.server :as nrepl-server]) ;; This is enough to prevent the script from exiting
  )

(println "Hello world")

(defn -main [& args]
  (println "Args:" args)

  (require 'nrepl.server)
  (nrepl.server/start-server :port 7882) ;; This doesn't work, seems that you can only call (require...) at top level?
  
  )

l0st3d12:01:15

the nrepl.server/start-server call doesn't compile because that namespace isn't available when you're compiling the -main fn ... I think you need to use something like requiring-resolve ...

l0st3d12:01:14

maybe something like

(let [start-repl (requiring-resolve nrepl.server/start-server)]
  (start-repl :port 7882))