Skip to content

Commit

Permalink
fix REPL result buffering so it actually buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
thheller committed Aug 13, 2019
1 parent b0a1aa8 commit 38d3366
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main/shadow/cljs/devtools/server/repl_impl.clj
Expand Up @@ -35,6 +35,7 @@

(:repl/require-error :repl/invoke-error)
(println (or (:stack result)
(:error result)
(:message result)))

:repl/set-ns-complete
Expand Down
24 changes: 14 additions & 10 deletions src/main/shadow/cljs/devtools/server/worker/impl.clj
Expand Up @@ -332,22 +332,26 @@
;; want to buffer all results before replying to whoever sent the initial REPL msg
(let [buffer-ref (->> actions
(map (juxt :id identity))
(into {})
(into {::pending (count actions)})
(atom))]

(fn [worker-state {:keys [id] :as result}]
(swap! buffer-ref assoc-in [id :result] result)

;; once all replies have been received send response
(let [buf @buffer-ref]
(when (= (count buf)
(count actions))
(let [buf (swap! buffer-ref
(fn [buf]
(-> buf
(update ::pending dec)
(assoc-in [id :result] result))))]

;; once all replies have been received send response
(when (zero? (::pending buf))
;; FIXME: should this just send one message back?
;; REPL client impls don't really need to know about actions?
;; just need to preserve some info from the input actions before they were sent to the runtimes (eg. warnings)
(>!! result-chan (->> (vals buf)
(sort-by :id)
(vec)))
(let [result (->> (dissoc buf ::pending)
(vals)
(sort-by :id)
(vec))]
(>!! result-chan result))
(async/close! result-chan)))

worker-state)))
Expand Down

0 comments on commit 38d3366

Please sign in to comment.