   [prj-key bld-ids]
   (let [c (chan)
         child (spawn "lein cljsbuild once" (convert-cwd prj-key))
-        error-msg (atom "")
-        inside-error? (atom false)]
+        inside-error? (atom false)
+        err-msg-buffer (atom "")
+        err-msg-timeout nil]
     (.setEncoding (.-stderr child) "utf8")
     (.setEncoding (.-stdout child) "utf8")
-    (.on (.-stderr child) "data" #(on-console-output % c error-msg inside-error?))
-    (.on (.-stdout child) "data" #(on-console-output % c error-msg inside-error?))
+    (.on (.-stderr child) "data"
+      #(on-console-output % c inside-error? err-msg-buffer err-msg-timeout))
+    (.on (.-stdout child) "data"
+      #(on-console-output % c inside-error? err-msg-buffer err-msg-timeout))
     (.on child "close" #(on-close-child c))
     ;; return the channel
     c))

(defn- on-console-output
  "This function gets called with chunks of text from the compiler console output.
   It parses them using regex and puts the results onto a core.async channel."
  [text1 c error-msg inside-error?]
  (let [text2 (trim text1)
        output-type (determine-output-type text2)]

    ; (js-log "raw output:")
    ; (js-log text2)
    ; (if output-type
    ;   (js-log (str "### output type: " output-type)))
    ; (js-log "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

    ;; close the error sequence if we catch any signal
    (when (and output-type @inside-error?)
      (reset! inside-error? false)
      (put! c [:error (extract-error-msg @error-msg)]))

    ;; concatenate error message
    (when @inside-error?
      (swap! error-msg str text1))

    ;; start error signal
    (when (= output-type :start-error)
      (reset! inside-error? true)
      (reset! error-msg text2)
      ;; send an "end error" signal 25ms from start of the error
      (js/setTimeout
        #(on-console-output end-error-msg c error-msg inside-error?) 25))

    ;; start compiling signal
    (when (= output-type :start)
      (put! c [:start (extract-target-from-start-msg text2)]))

    ;; compilation success
    (when (= output-type :success)
      (put! c [:success (extract-time-from-success-msg text2)]))

    ;; warnings
    (when (= output-type :warning)
      (put! c [:warning (extract-warning-msgs text2)]))))

(defn- on-close-child [c]
  (put! c [:finished])

  [prj-key bld-ids]
  (let [c (chan)
        child (spawn "lein cljsbuild auto" (convert-cwd prj-key))
        inside-error? (atom false)
        err-msg-buffer (atom "")
        err-msg-timeout (atom nil)]
    (.setEncoding (.-stderr child) "utf8")
    (.setEncoding (.-stdout child) "utf8")
    (.on (.-stderr child) "data"
      #(on-console-output % c inside-error? err-msg-buffer err-msg-timeout))
    (.on (.-stdout child) "data"
      #(on-console-output % c inside-error? err-msg-buffer err-msg-timeout))
    (.on child "close" #(on-close-child c))

    ;; save the child pid
