#!/bin/sh
"exec" "clojure" "-Sdeps" '{:deps {nrepl/nrepl {:mvn/version "1.3.1"}}}' "$0" "$@"
(require '[nrepl.core :as nrepl])
(with-open [conn (nrepl/connect :port 1339)]
(let [client (nrepl/client conn 1000)
a (nrepl/new-session client) ; two sessions, ONE connection
b (nrepl/new-session client)
ev (fn [s code] (->> (nrepl/message client {:op "eval" :session s :code code})
(keep :value) vec))]
(println "[A] (+ 40 2) =>" (ev a "(+ 40 2)"))
(println "[A] *1 =>" (ev a "*1"))
(println "[B] *1 =>" (ev b "*1") " <- same conn, diff session")
(println "[B] (+ 1 1) =>" (ev b "(+ 1 1)"))
(println "[A] *1 =>" (ev a "*1") " <- B clobbered A")))
Right now, *1 gets shared between sessions. nrepl spec says that session ThreadLocals should be isolated from one another, e.g. *1. This matters if tooling is performing background eval on your behalf and the user unexpectedly receives different values for *1, *e, etc.
Right now,
*1gets shared between sessions. nrepl spec says that session ThreadLocals should be isolated from one another, e.g.*1. This matters if tooling is performing background eval on your behalf and the user unexpectedly receives different values for*1,*e, etc.