1.3.0 permalink Arrow_down_16x16

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.

1 Example top

  • (def *agnt* (agent {}))
    
    user=> (send-off *agnt* (fn [state] 
                              (Thread/sleep 10000)
                              (assoc state :done true)))
    #<Agent@5db18235: {}>
    
    user=> (await *agnt*) ; blocks till the agent action is finished
    nil
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2855 top

(defn await
  "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."
  {:added "1.0"
   :static true}
  [& agents]
  (io! "await in transaction"
    (when *agent*
      (throw (new Exception "Can't await in agent action")))
    (let [latch (new java.util.concurrent.CountDownLatch (count agents))
          count-down (fn [agent] (. latch (countDown)) agent)]
      (doseq [agent agents]
        (send agent count-down))
      (. latch (await)))))
Vars in clojure.core/await:
Used in 0 other vars

Comments top

No comments for await. Log in to add a comment.