Fork me on GitHub
#babashka
<
2024-05-25
>
neilyio21:05:47

I'm trying to understand a difference I'm seeing between running clj and running bb on the command line. I have this simple file, repl.clj:

(require '[clojure.core.server :as server])

(server/start-server
 {:name          "repl"
  :port          1666
  :accept        'clojure.core.server/repl
  :server-daemon false})
If I run clj repl.clj, a socket repl server starts up, and I can successfully run echo "(+ 2 2)" | nc localhost 1666 to eval a form. If I run bb repl.clj, the program exits immediately, and no server starts up. Is this expected? Do I need to do something else with bb? For context, I'm manually trying to setup a bb socket repl so I can customize some things about it (like the prompt), as I'm experimenting with sending forms from the Helix editor using nc.

borkdude21:05:33

Just add a @(promise) at the end of the script

borkdude21:05:59

The call to server/start-server isn't blocking, this is why the script terminates

borkdude21:05:28

in clj, the JVM Clojure process waits for any non-daemon threads to finish I believe

neilyio21:05:17

Oh nice, thank you so much, I see that in the book now. And thanks for explaining the difference, is not-waiting for non-daemon threads just a GraalVM thing?

borkdude21:05:53

bb calls (shutdown-agents) at the end of the main function, that might be the difference

neilyio21:05:19

I'll keep that in mind! Thanks again.