开发者

:reload-all and existing references

开发者 https://www.devze.com 2023-02-18 20:23 出处:网络
I just discovered an interesting feature of :reload-all. Say I have: (defn clock-update [clock] (swap! clock (fn [previousTime] (+ previousTime 1) )))

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消