Reputation: 47441
As I understand clojure STM can be used for transacting values across refs.
I understand this property is useful in datastores, where 2 or more locations have to be mutated in a single transaction - atomicity.
However in what cases will this be useful in software applications ? I could just store all my state in one map and use an clojure.core/atom if I want shared mutable state.
In what types of applications / scenarios will usage of refs make sense over atoms or other state primitives in clojure.
Upvotes: 1
Views: 138
Reputation: 4368
Using an atom is indeed what's suggested in the Elements of Clojure book by Zach Tellman (chapter 2 - If you have mutable state, use an atom). They say that until ~60% utilization of the stateful container, an atom is probably a better choice. The advice is summarized at the end of the section as:
Upvotes: 2