Skip to content

Instantly share code, notes, and snippets.

@danielsz
Created January 10, 2020 20:11
Show Gist options
  • Save danielsz/c8303fb2aaa4e08df012d90b372c05cc to your computer and use it in GitHub Desktop.
Save danielsz/c8303fb2aaa4e08df012d90b372c05cc to your computer and use it in GitHub Desktop.
nrepl from clojure
(ns nrepl
(:require [nrepl.core :as nrepl])
(:import [java.net ConnectException]))
(defn nrepl-send [repl-port x]
(let [message (cond
(string? x) {:op "eval" :code x :id (utils/uuid)}
(map? x) x
:else (throw (AssertionError. "Wrong input.")))]
(with-open [conn (nrepl/connect :port repl-port)]
(-> (nrepl/client conn 1000)
(nrepl/message message)
doall
;println
)
true)))
(defn connected?
([repl-port]
(let [handshake #(try
(nrepl-send repl-port {:op "eval" :code "(+ 2 3)"})
(catch ConnectException e false))]
(connected? handshake 18000)))
([f timeout]
(loop [n 0]
(cond
(f) true
(> n (/ timeout 200)) false
:else (do
(Thread/sleep 200)
(recur (inc n)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment