On Wed, Jul 7, 2010 at 5:04 PM, Meikel Brandmeyer <m...@kotka.de> wrote:
> Hi, > > Am 07.07.2010 um 22:46 schrieb Brian Hurt: > > > I'm wondering if the following pattern is safe or not. I'm in a > transaction, and I want to create an agent and then send it an initializing > message (the message function isn't transaction-safe, so I don't want to run > it in the transaction). So I want to do something like: > > > > (def my-ref (ref nil)) > > > > (defn example [ f ] > > (dosync > > (if (nil? @my-ref) > > (let [ a (agent nil) ] > > (ref-set my-ref a) > > (send a init-function) > > (send a f)) > > (send @my-ref f)))) > > > > (actually, what I want to do is rather more complicated than this, but > this demonstrates the problem). So, my question is: is it guaranteed that > init-function will be received by the agent before any f functions are > received? > > The ordering of sends will be preserved, although they will be scheduled > after the transaction commits. > > It might be due to the simplified example, but... Why don't you just > initialise your agent when you create it? > > This is due to the simplified example. I'm actually creating a map of keys to soft references to agents (and removing the references and keys from the map when the agents are reclaimed), which allows me to generate agents only when I need them, and have them freed when they are no longer needed. (def my-ref (agent (init-function))) > > (defn example > [f] > (send @my-ref f)) > > Sincerely > Meikel > > -- > 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<clojure%2bunsubscr...@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 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