Any idea why changes in the function below does'nt work (see first post on
this topic)?
(defn process-request
[offer args]
(logger/log "process called")
(let [offer-value (Double/parseDouble (:offer offer))
out-queue (:out-queue args)
unique-offers (:unique-offers args)
all-offers (:all-offers args)
streams (:streams offer)]
(dosync
(cond
(empty? @unique-offers)
((logger/log "map" @unique-offers)
(alter unique-offers assoc offer-value streams))
:else (logger/log "error")))))
On Tue, Apr 26, 2011 at 11:38 PM, Jonathan Fischer Friberg <
[email protected]> wrote:
> Yes, you're right, I'm wrong. :)
> The derefs must be in the dosync block. (which I somehow assumed, oh well)
>
>
> On Tue, Apr 26, 2011 at 11:17 PM, Daniel Werner <
> [email protected]> wrote:
>
>> On Apr 26, 10:52 pm, Jonathan Fischer Friberg <[email protected]>
>> wrote:
>> > No, that isn't possible.http://clojure.org/refs
>>
>> I disagree: In the example given, dereferencing happens outside the
>> dosync block, thus outside of any transaction, so a race where map1
>> and map2 change midway through the #'and expression is theoretically
>> possible. For this reason, #'deref/@ and #'alter are best kept in the
>> same transaction in this situation.
>>
>> > Inside a transaction (a dosync call), values updated in another
>> transaction
>> > wont be seen. This means that the first transaction wont see the change
>> > until it commits, at that moment it realizes that the ref that were
>> altered
>> > was changed outside of that particular transaction, and retries. All of
>> this
>> > happens automatically, so you wont have to worry.
>>
>> --
>> 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
>>
>
> --
> 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
>
--
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