Skip to content

clojure.core/await

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 2 Runnable: 0
([& agents])

Blocks the current thread (indefinitely!) until all actions dispatched thus far, from this thread or agent, to the agent(s) have occurred. Will block on failed agents. Will never return if a failed agent is restarted with :clear-actions true or shutdown-agents was called.

Examples

by ghoseb on . May have evaluation errors.
by phreed on . May have evaluation errors.

Note by andrewni420

;;It is not actually allowed to await on an action dispatched from an agent to an agent

(def m (agent 0))
(def n (agent 0))

(defn step 
  [agent1 agent2]
  (try (await (send agent2 inc))
       (catch Exception e (println e)))
  agent1)

;;Evaluating this throws an error saying "Can't await in agent action"
(send m #(step % n))

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.