:reload-all and existing references
I just discovered an interesting feature of :reload-all
. Say I have:
(defn clock-update [clock] (swap! clock (fn [previousTime] (+ previousTime 1) ) ) )
(def threads (Executors/newScheduledThreadPool 16))
(defn start-clock [clock]
(. threads scheduleAtFixedRate
#(clock-update clock) 0 1 TimeUnit/SECONDS ))
and I (start-clock clock)
where clock is an atom I'm watching, WELL, if I then change the atom swap! function (say, change + for -) in clock-update and (use :reload-all 'myns)
then guess what, that function is used to update the atom for existing threads instea开发者_StackOverflow社区d! I didn't expect that. I thought existing threads would continue to reference whatever function they were constructed with.
As the documentation explains
def always applies to the root binding, even if the var is thread-bound at the point where def is called.
精彩评论