Created
February 1, 2022 11:26
-
-
Save marcomorain/07d081d3054974009be3816baf5d085f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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