On 20/11/13 19:36, juan.facorro wrote:
The value for all refs whose value you don't actually modify inside a transaction should be obtained through ensure <http://clojuredocs.org/clojure_core/clojure.core/ensure>if you want to make sure :P their value won't be changed by a different transaction, that way you get a consistent value when the current transaction is finally committed.

ok this is an interesting and relevant for me comment....let's take a step back. Assume the same bank from my previous example and consider the following function:

(defn total!
"Sum all accounts safely with a consistent view even if other transactions are still running."
 [bank]
   (dosync
     (reduce +'
       (map (comp :curr-balance second) *@bank*))))

What would be the implications of changing the bold bit to *(ensure bank) *?

On a slightly different note, is the mega-ref (the entire map in a ref) approach generally suggested ? I initially had a map-ref with agents inside (the accounts) but I find it a lot simpler to just have the map-ref...what ref-granularity are people suggesting for the bank example?


Jim

--
--
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
--- You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to