1.3.0 permalink Arrow_down_16x16

await-for

clojure.core

  • (await-for timeout-ms & agents)
Blocks the current thread until all actions dispatched thus
far (from this thread or agent) to the agents have occurred, or the
timeout (in milliseconds) has elapsed. Returns nil if returning due
to timeout, non-nil otherwise.

0 Examples top

Log in to add / edit an example.

See Also top

  • 0
    clojure.core/await

    Blocks the current thread (indefinitely!) until all actions dispatc

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2877 top

(defn await-for
  "Blocks the current thread until all actions dispatched thus
  far (from this thread or agent) to the agents have occurred, or the
  timeout (in milliseconds) has elapsed. Returns nil if returning due
  to timeout, non-nil otherwise."
  {:added "1.0"
   :static true}
  [timeout-ms & agents]
    (io! "await-for 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  timeout-ms (. java.util.concurrent.TimeUnit MILLISECONDS))))))
Vars in clojure.core/await-for:
Used in 0 other vars

Comments top

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