You cannot directly access the STM value history. But you can use add-watch to record the history of values:
(def a-history (ref [])) (def a (agent 0)) (add-watch a :my-history (fn [key ref old new] (alter a-history conj old)))
Each time a updated (transaction stm is committed), the old value will be associated with the sequence stored in a-history .
If you want to access all intermediate values, even for rollback transactions, you can send values ββto the agent during the transaction:
(def r-history (agent []) (def r (ref 0)) (dosync (alter r (fn [new-val] (send r-history conj new-val) ;; record potential new value (inc r)))) ;; update ref as you like
After the transaction is completed, all changes to the r-history agent will be made.
ordnungswidrig
source share