Skip to content

Instantly share code, notes, and snippets.

@marcomorain
Created February 1, 2022 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcomorain/07d081d3054974009be3816baf5d085f to your computer and use it in GitHub Desktop.
Save marcomorain/07d081d3054974009be3816baf5d085f to your computer and use it in GitHub Desktop.
(ns binding
(:import java.util.concurrent.Executors))
(def thread-pool
(Executors/newFixedThreadPool 1))
(set-agent-send-off-executor! thread-pool)
(def counter (agent 0))
(add-tap println)
(def ^:dynamic *some-context* nil)
(tap> "start")
(defn inspect []
(tap>
(format "tap: thread=%s context=%s"
(.getId (Thread/currentThread))
*some-context*)))
(binding [*some-context* "in the agent"]
(send-off counter (fn [& _]
(inspect))))
(.submit thread-pool inspect)
;; Output
;; start
;; tap: thread=43 context=in the agent
;; tap: thread=43 context=in the agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment