Managing states with agents
To safely manage a mutable state in a multithreaded program, Clojure offers agents. Each agent is responsible for managing one object that contains its state. Most often, a state object will be stored in one of Clojure's own immutable data structures. To change the state of a particular agent, an action can be sent to it. Actions are ordinary, non-blocking functions that are executed by the agent. The return value of the action will replace the current state of the agent.
Agents run in a thread provided by an internal thread pool that is managed by Clojure. They are built to be responsive; Clojure will never place locks while handling actions. The agent's state can safely be read at any time by other code, no matter on which thread it is running. An action is sent to the agent asynchronously and is picked up later by the agent's thread. The agent's thread will execute the action and its result value will become the agent's new state.
It is possible to add a validator...