On Wed, Sep 23, 2009 at 10:17 AM, Christophe Grand
<christo...@cgrand.net> wrote:
>
>
> On Wed, Sep 23, 2009 at 7:14 AM, Timothy Pratley <timothyprat...@gmail.com>
> wrote:
>>
>> When it useful to be able to deref inside a dosync without ensuring?
>
>
> In a read-only transaction.
>
>
>>
>> Ensure seems like a more safe default of what I'd expect from a
>> transaction. So why not make deref automatically ensure within a
>> dosync? It takes a bit of care to remember to use ensure instead of
>> deref in a dosync.
>
> You only need to ensure if you don't use alter or ref-set later.
>
> The typical use case for ensure is:
> (when (a-predicate? (ensure foo)) (alter bar f arg1 arg2))
>

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
which we accept fewer guarantees of lockdown rather than more if we
want to get more concurrency. ensure pulls things into your
transaction footprint that plain reads would not. For instance, giving
a salesperson a bonus equal to 10% of their year-to-date sales need
not lock down their sales - it's merely a calculation done at a point
in time, while allowing sales to proceed.

Rich

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