Browse Clojure Foundations for Java Developers

Asynchronous Tasks with Agents

Use agents to apply state updates asynchronously, one action at a time.

Agents manage state like atoms, but updates happen asynchronously. You “send” a function to an agent, and the agent applies those functions in order.

This makes agents useful for:

  • background updates that should be serialized
  • offloading slow work from request threads
  • simple “actor-like” state ownership
1(def events (agent []))
2(send events conj {:type :login :user/id 42})

Java mental model: an agent is like a single-threaded executor plus a state value. You enqueue an update function; the agent applies it later.

In this section

Revised on Friday, April 24, 2026