#!/usr/bin/env boot
(set-env! :dependencies '[[org.clojure/tools.nrepl "0.2.11"]])
(require '[clojure.tools.nrepl.server :as repl])
(defonce nrepl-server (atom nil))
(defn start-nrepl-server []
(println "REPL: start!")
(reset! nrepl-server (repl/start-server :port 8628)))
(defn stop-nrepl-server []
(println "REPL: stopping....")
(repl/stop-server @nrepl-server)
(reset! nrepl-server nil))
(def counter (atom 0))
(defn app []
(while true
(swap! counter inc)
(println @counter)
(Thread/sleep 1000)))
(defn -main [& args]
(start-nrepl-server)
(app))
;;; 1. Run this script
;;; ↓ run following in your terminal emulator.
;;; % ./embedded-nrepl-server.clj
;;; You'll see counting up number.
;;; 2. Connect with the nREPL server.
;;; ↓ eval following in your Emacs.
;;; M-: (cider-connect "localhost" 8628)
;;; Port number 8628 correspond with argument to the repl/start-server above.
;;; 3. Change namespace
;;; ↓ eval following in your Emacs.
;;; M-: (cider-repl-set-ns "boot.user")
;;; 4. Check if I connect with the nREPL server running on port number 8628 and `app` is running.
;;; ↓ eval following in your cider-repl.
;;; @counter
;;; It will correspond with the number that just have counted in your terminal emulator.