Agents build on the STM, and each agent acts a lot like a reference. You use agents by sending the agent messages—functions that manipulate the agent's state—and those are run in the thread pool.
We create agents with the agent
function, and we send messages to them with send
and send-off
. Whatever the function returns is the agent's new state value.
For this recipe, we'll again solve the same problem we did in the last recipe, Managing program complexity with STM.
We will include the same references in the project.clj
file and the same requirements in the REPL as we did in the Managing program complexity with STM recipe. We will also use the same input file, bound to the name data-file
again.
And we'll also use several utility functions from the last recipe: lazy-read-csv
, with-header
, ->int
, sum-item
, and sum-items
.