         writer     (t/writer :json)
 
         finally-fn (fn []
-                     (debugf "Cleaning up WebWorker (worker thread? %s)" (worker?))
+                     (debugf "Cleaning up WebWorker %s" (worker-type))
                      (close! input-ch)
                      (close! output-ch)
                      (when close-fn

(def script-name "js/repl-thread.js")

(defn worker? []
  (undefined? (.-document js/self)))

(defn- deserialize [reader msg]
  (some->> (.-data.msg msg)
           (t/read reader)))

(defn- serialzie [writer msg]
  (debugf "Serialize: %s %s" (if (worker?) :worker :master) msg)
  (let [msg (t/write writer msg)]
    (js-obj "msg" msg)))


      (loop []
        (when-let [msg (<! input-ch)]
          (try
            (.postMessage target (serialize writer msg))
            (catch js/Error e
              (.postMessage target (serialize writer [:webworker/error nil (str e)]))))
          (recur)))
      (finally-fn))
    {:input-ch  input-ch
