await
does exactly this:
(clojure.repl/doc await)
clojure.core/await
([& 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.
To try it out:
(def a (agent 0))
(dotimes [_ 100] (send-off a (fn [x] (Thread/sleep 30) (inc x))))
(await a)
(Will block for a few seconds)