Quite right that is an important distinction.
On Oct 8, 5:21 pm, Krukow <[email protected]> wrote: > On Oct 8, 3:43 am, Timothy Pratley <[email protected]> wrote: > > > Atoms can't do this, as they are synchronous (called and returned > > immediately) - hence the warning about potentially being called > > multiple times. > > The reason that swap! may "fail" is that it is performing a compare- > and-swap operation which may fail in a concurrent setting; the > function passed to swap is retried if this happens. > > An approach that might work for you depending on your situation is to > send to an agent which asynchronously does the swap. > > (def a (atom 40)) > (def queue (agent nil)) > > (def r1 (ref 0)) > (def r2 (ref 0)) > > (dosync > (let [v1 (alter r1 inc) > v2 (alter r2 inc)] > (send queue (fn [_] (swap! a #(+ v1 v2 %)))))) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
