Merge pull request #4 from jolt-lang/nrepl-port-cleanup

nrepl: remove .nrepl-port on exit
This commit is contained in:
Dmitri Sotnikov 2026-06-06 11:25:36 +08:00 committed by GitHub
commit 6a1706df10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -300,11 +300,17 @@
(eval-string ctx (string "(jolt.nrepl/start-server! {:host \"" host "\" :port " port "})"))
# Editors auto-discover the port from this file (nREPL convention).
(spit ".nrepl-port" (string port))
# Remove .nrepl-port on exit — on a clean unwind (defer) and on Ctrl-C/SIGTERM
# (signal handlers). A hard SIGKILL can't be caught, so it may still be left.
(def cleanup (fn [&] (protect (os/rm ".nrepl-port"))))
(os/sigaction :int (fn [&] (cleanup) (os/exit 0)) true)
(os/sigaction :term (fn [&] (cleanup) (os/exit 0)) true)
(print "Jolt nREPL server started on " host ":" port)
(print "Wrote .nrepl-port — connect your editor; Ctrl-C to stop.")
(flush)
# Keep the main fiber alive so the event loop serves connections.
(forever (ev/sleep 60)))
(defer (cleanup)
(forever (ev/sleep 60))))
(defn- print-version []
(print "jolt v" jolt-version))