Created
January 10, 2020 20:11
-
-
Save danielsz/c8303fb2aaa4e08df012d90b372c05cc to your computer and use it in GitHub Desktop.
nrepl from clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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