liveBook · Manning

Await

As explained in Clojure: The Essential Reference

await is a Clojure function that blocks until one or more agents have completed their currently queued actions.

await blocks until one or more Clojure agents finish their currently queued actions. Pass any number of agent instances; it returns nil after they complete. section 14.6

Wait for several agents

(def a (agent 10000)) (def b (agent 10000)) (send a slow-update) (send b slow-update) (await a b) ;; nil The call waits for both agents. Use await-for instead when a timeout is required; it returns false when the timeout expires.

How Clojure: The Essential Reference covers it

How deep it goes
Defines blocking, multiple-agent input, and nil completion, but defers timeout behavior to await-for.
Examples
Demonstrates waiting for two slow agents and awaiting a collection of alphabet-counting agents.
What it assumes
Assumes familiarity with agents, asynchronous actions, sending functions, and dereferencing agent state.
What you can do after
Operate agent workflows by waiting for dispatched actions before reading their completed state.
How it connects
Connects agents with send, deref, and await-for for dispatching, observing, and timing asynchronous state changes.

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.