Hello,

I tried to call an agent inside a dosync and wait on a Java semaphore
for its completion.
[I tried clojure's await but that gave nasty exceptions]
Can anyone explain, why wait-for-agent works as I expected while the
code in wait-for-agent/dosync seems to block ?

Regards

(defn awake [_ semaphore]
  (println "Release semaphore")
  (.release semaphore)
  _)

(defn wait-for-agent []
  (let [a (agent :void)
        sema (java.util.concurrent.Semaphore. 0)]
    (println "Wait for agent")
    (send a awake sema)
    (.acquire sema)
    (println "Ready")))

(defn wait-for-agent/dosync []
  (let [a (agent :void)
        sema (java.util.concurrent.Semaphore. 0)]
    (dosync
       (println "Wait for agent")
       (send a awake sema)
       (.acquire sema)
       (println "Ready"))))

(wait-for-agent)
(wait-for-agent/dosync)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to