On Dec 23, 2008, at 3:40 PM, CuppoJava wrote:
I'm a little confused about the (send-off *agent* update) line though. So as I understand it, *agent* is identical to my-agent, while running inside update. Is that correct?
That is correct. Only one agent can be running on a thread at a given time and *agent* is bound to it during the message function. The reason for update to use *agent* rather than my-agent is that *agent* works with any agent, so update is generic.
And is there any guarantee that the second send-off (send-off *agent* update) won't run until update has finished running?
Yes, that is guaranteed. [ As of today (svn 1185 of Clojure) Rich added a way to explicitly send them early (with "release-pending- sends"), but the default is that they're held until the end. See his message to the google group today. ]
What's stopping from the send-off from executing immediately?
It's part of the design of agents. Those messages are guaranteed not to be sent until your update function completes and *agent* has its new value.
http://clojure.org/agents is the best reference for all things agent. --Steve
smime.p7s
Description: S/MIME cryptographic signature