Wrapping Up
In this chapter we looked at Clojure’s trio of state-management constructs: the atom, the ref, and the agent. We saw that the atoms, refs, and agents have a lot in common. Each one is just a mutable container for a value. Each lets you march from one value to the next by supplying a function—a function that takes the old value and produces the new one. But atoms, refs, and agents part company in the way they manage change. Atoms are simple, stand-alone containers that march from one value to the next, resolving any conflicts by reevaluating the update function. Refs are just like atoms, but can be updated in batches, inside of a dosync transaction. Agents are stand-alone, but queue up updates and execute them one at a time in a separate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access