Hi, I gave it a try to find a solution to your problem. I ended up
using a single atom to hold the produced data and as means to detect
that consuming started (by swapping in a fn wrapping the produced
value). Don't know wether this fits your problem better than the one
already posted.

(def data (atom []))

(defn produce [data-atom]
  (Thread/sleep 100)
  (when (vector? (swap! data #(if (vector? %) (conj % :foo) %)))
    (recur data-atom)))

(defn consume [data-atom]
  ((swap! data-atom #(if (vector? %) (fn [] %) %))))

(defn produce-consume-test []
  (dotimes [n 100]
    (future-call #(produce data)))
  (Thread/sleep 1000)
  (consume data))

(do (swap! data (constantly []))
    (count (produce-consume-test)))

--~--~---------~--~----~------------~-------~--~----~
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