> And even then, ensure is often not needed and overkill. Make sure you
> have a real business requirement that the predicate remain true (or
> value fixed) on transaction completion. We need to move to a world in
--------------
It seems that my problem falls exactly in this category. Ensuring
*consuming* prohibits that the consumer misses messages added to
*data* . At least I hope that it does.
(def *data* (ref ()))
(def *consuming* (ref false))
(def *is-syncing* (ref true))
(def *consumer-agent* (agent '()))
(defn data-producer [value]
(if @*is-syncing*
(if (dosync
(if (ensure *consuming*)
true
(do
(alter *data* conj value)
false)))
(do
(loop []
(Thread/sleep 100)
(if @*is-syncing*
(recur)))))))
(defn producer []
(doseq [i (range 10000)]
(data-producer i)))
(defn consume [agent]
(Thread/sleep 150)
(dosync
(ref-set *consuming* true))
(println "Consuming started, " (count @*data*) " items to consume.")
(Thread/sleep 250)
(dosync
(ref-set *consuming* false)
(ref-set *is-syncing* false)))
(defn consumer []
(send-off *consumer-agent* consume))
(doseq [i (range 300)]
(future-call producer))
(consumer)
(shutdown-agents)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---