              (js/CLOSURE_IMPORT_SCRIPT
                (aget (.. js/goog -dependencies_ -nameToPath) name))))))))
 
-(defrecord JscEnv [host port socket response-channel]
+(defrecord JscEnv [host port socket response-promise]
   repl/IJavaScriptEnv
   (-setup [this opts]
     (setup this opts))

  (.write out (int 0)) ;; terminator
  (.flush out))

(defn read-messages [^BufferedReader in response-channel]
  (loop [sb (StringBuilder.) c (.read in)]
    (cond
      (= c -1) (do
                 (when-let [ch @response-channel]
                   (deliver ch :eof))
                 :eof)
      (= c 1) (do
                (print (str sb))
                (flush)
                (recur (StringBuilder.) (.read in)))
      (= c 0) (do
                (deliver @response-channel (str sb))
                (recur (StringBuilder.) (.read in)))
      :else (do
              (.append sb (char c))

  (.start
        (Thread.
          #(try
            (let [rv (read-messages (:in @(:socket repl-env)) (:response-promise repl-env))]
              (when (= :eof rv)
                (close-socket @(:socket repl-env))))
            (catch IOException e
