             (recur)
 
             (= :repl/quit form)
-            (do (do-repl-quit state-ref session)
+            (do (do-repl-quit session)
                 (send msg {:value ":repl/quit"
                            :printed-value 1
                            :ns (-> *ns* ns-name str)}))
 
             (= :cljs/quit form)
-            (do (do-repl-quit state-ref session)
+            (do (do-repl-quit session)
                 (send msg {:value ":cljs/quit"
                            :printed-value 1
                            :ns (-> *ns* ns-name str)}))

    (log/debug ::send res)
    (transport/send transport res)))

(defn do-repl-quit [state-ref session]
  (let [session-id (-> session meta :id)
        {:keys [clj-ns watch-chan]} (get @state-ref session-id)]

    (swap! state-ref dissoc session-id)
    (async/close! watch-chan)

    (swap! session assoc
      #'*ns* clj-ns
      #'cider.piggieback/*cljs-compiler-env* nil)))

(defn worker-exit [state-ref session msg]
  (do-repl-quit state-ref session)

  ;; replying with msg id that started the REPL, not the last msg
  (send msg {:err "\nThe REPL worker has stopped.\n"})

    ;; cleanup if worker exits
    (go (<! proc-stop)
        (async/close! watch-chan)
        (worker-exit session msg))

    ;; watch worker for specific messages (ie. out/err)
    ;; send :err/:out with latest msg id to make tools happy
