I was messing with the example at clojure.org/agents to get it to log which
agents called which, and finally came up with
(use 'clojure.pprint)
(defn relay [x i agidx]
(when (:next x)
(send (:next x) relay i (:idx x)))
(when (and (zero? i) (:report-queue x))
(.put (:report-queue x) i))
(assoc x :calls (conj (:calls x) [i agidx]))
)
(defn run [m n]
(let [q (new java.util.concurrent.SynchronousQueue)
hd (reduce (fn [next _]
(agent {:next next :calls [] :idx _}))
(agent {:report-queue q :calls [] :idx -1})
(range (dec m)))]
(doseq [i (reverse (range n))]
(send hd relay i nil))
(.take q)
(pprint hd)
))
(time (run 10 10))
This code works, but if I replace the last line of the relay function with
"(agent (assoc x :calls (conj (:calls x) [i agidx])))", execution hangs. I
now realize it was wrong-headed to wrap the result up in another agent, but
I am curious about what causes it to hang if you do so, rather than return
an error.
Best regards,
Alex
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en