braveandtrue

https://www.braveclojure.com/
jeffh-fp 2017-02-13T20:29:21.000024Z

(defn sleep-print-update
  [sleep-time thread-name update-fn]
  (fn [state]
    (Thread/sleep sleep-time)
    (println (str thread-name ": " state))
    (update-fn state)))
(def counter (ref 0))
(future (dosync (commute counter (sleep-print-update 100 "Thread A" inc))))
(future (dosync (commute counter (sleep-print-update 150 "Thread B" inc))))
Here’s a timeline of what prints:
Thread A: 0 | 100ms
Thread B: 0 | 150ms
Thread A: 0 | 200ms
Thread B: 1 | 300ms

jeffh-fp 2017-02-13T20:29:28.000025Z

from Chapter 10

jeffh-fp 2017-02-13T20:29:49.000026Z

I'm confused why println is called twice

jeffh-fp 2017-02-13T20:29:53.000027Z

(per thread)

jeffh-fp 2017-02-13T20:31:15.000028Z

commute shouldn't be retrying the "transaction"