Skip to content

Commit

Permalink
Wait for nrepl server to start.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Feb 7, 2012
1 parent 75a062d commit 1b9e1b5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/leiningen/repl.clj
Expand Up @@ -5,20 +5,21 @@
[clojure.java.io :as io]
[leiningen.core.eval :as eval]
[leiningen.core.classpath :as classpath]))

(defn- start-server [project port]
(eval/eval-in-project project
`(clojure.tools.nrepl/start-server ~port)
'(require 'clojure.tools.nrepl)))
`(.get (nth (clojure.tools.nrepl/start-server ~port) 1))
'(require 'clojure.tools.nrepl)))

(defn get-port []
(Integer.
(or (System/getenv "LEIN_REPL_PORT")
(dec (+ 1024 (rand-int 64512))))))
(Integer.
(or (System/getenv "LEIN_REPL_PORT")
(dec (+ 1024 (rand-int 64512))))))

(defn repl
([] (repl nil))
([project]
(let [port (get-port)]
(start-server project port)
(reply/launch-nrepl {:attach (str port)}))))
(let [port (get-port)]
(future (start-server project port))
(Thread/sleep 4000)
(reply/launch-nrepl {:attach (str port)}))))

0 comments on commit 1b9e1b5

Please sign in to comment.