e.g.
Try two commands on the repl:
(defn worker []
(Thread/sleep 2000)
(prn "not working"))
user> worker
#<user$worker__319 user$worker__319@cbb3fa>
user> (var worker)
#'user/worker
user> #'worker
#'user/worker
The reader macro #'x expands to (var x). If you have the following function which calls the worker function in a thread:
(defn worker-thread [worker-fn]Launch the worker thread
(.start (Thread. #(dotimes [i 10] (worker-fn)))))
user> (worker-thread worker)
Fix the worker function:
(defn worker []You will see that the thread still printing "not working" every 5 seconds.
(Thread/sleep 2000)
(prn "working"))
If you had launched the worker thread as follows:
user> (worker-thread #'worker)
and now you fix the function:
(defn worker []Thread will now print the new "really printing" message.
(Thread/sleep 2000)
(prn "really working"))
wonderful example!
ReplyDelete