Skip to content

Commit

Permalink
Prevent leaky tap-fns by using a defonce #550
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Jan 14, 2024
1 parent 4237619 commit 8ba9bb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions fnl/conjure/client/clojure/nrepl/server.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,21 @@
(.. "(def tap-queue-size " queue-size ")")
"(defonce tap-queue! (atom (list)))"

"(defn enqueue-tap! [x]"
" (swap! tap-queue! bounded-conj x tap-queue-size))"

"(defn dump-tap-queue! []"
" (reverse (first (reset-vals! tap-queue! (list)))))"
;; Must be a defonce so that we always have the same function
;; reference to remove-tap and add-tap. If we make a new
;; function each time we'll end up adding more and more tap
;; functions.
"(defonce enqueue-tap!"
" (fn [x] (swap! tap-queue! bounded-conj x tap-queue-size)))"

;; No setup for older Clojure versions.
"(when (resolve 'add-tap)"
" (remove-tap enqueue-tap!)"
" (add-tap enqueue-tap!))"

"(defn dump-tap-queue! []"
" (reverse (first (reset-vals! tap-queue! (list)))))"

"(in-ns initial-ns)"])}
(when cb
(nrepl.with-all-msgs-fn cb)))))
Expand Down
2 changes: 1 addition & 1 deletion lua/conjure/client/clojure/nrepl/server.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ba9bb0

Please sign in to comment.