Yeah, it's intended, just like what Ulrich showed. The same comment
appears on the doc of release-pending-sends.
In your case, the inner send-off doesn't rely on the result of the
outter send-off. So, you can use release-pending-sends.
The following code will have "hey" printed right away.

(send
  (agent nil)
  (fn [_]
    (send
      (agent nil)
      (fn [_]
        (println "Hey!")))
    (release-pending-sends)
    (Thread/sleep 4000)))
(shutdown-agents)

The interesting thing is, if you remove the call to (release-pending-
sends) and the call to (shutdown-agents) will cause
java.util.concurrent.RejectedExecutionException being thrown.
This is because, I think, when the outter send-off has finished
sleeping, shutdown-agents (which is really a call to shutdown on the
thread-pool agents used) will take effect, and the thread-pool is shut
down. Then, the inner send-off starts to work, but he will find that
the thread pool has already been turned off. So the exception is
thrown.

I don't know how to NOT call the release-pending-sends function, and
still be able to shutdown-agents. Would anyone tell me how?

On Jun 13, 3:46 am, Moritz Ulrich <ulrich.mor...@googlemail.com>
wrote:
> Sorry for the second mail, but here is the passage from clojure.org
> which mentions the behavior you've seen:
>
> "5. If during the function execution any other dispatches are made
> (directly or indirectly), they will be held until after the state of
> the Agent has been changed."
>
> Maybe it's done to prevent problems when the function the
> currently-active agent sent to another agent depends on the value of
> the original agent.
>
> On Sat, Jun 12, 2010 at 9:43 PM, Moritz Ulrich
>
>
>
> <ulrich.mor...@googlemail.com> wrote:
> > I'm not sure why it's doing this, but I read about this in the api
> > documentation - It's intended
>
> > On Sat, Jun 12, 2010 at 9:41 PM, Dan Larkin <d...@danlarkin.org> wrote:
> >> Hey all,
>
> >> I've cooked up this example code to demonstrate a point:
>
> >> (send-off
> >>  (agent nil)
> >>  (fn [_]
> >>   (send-off
> >>    (agent nil)
> >>    (fn [_]
> >>      (println "Hey!")))
> >>   (Thread/sleep 4000))) ; "Hey!" isn't printed for 4 seconds (when the 
> >> outer agent finishes).
>
> >> Which is that actions sent to an agent from another agent won't be started 
> >> until the first agent returns from its current action.
>
> >> Does anyone have insight as to the reasoning here? Is it a bug? If it's 
> >> intended behavior is there something I can do to circumvent it?
>
> >> Dan
>
> >> --
> >> 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
>
> > --
> > Moritz Ulrich
> > Programmer, Student, Almost normal Guy
>
> >http://www.google.com/profiles/ulrich.moritz
>
> --
> Moritz Ulrich
> Programmer, Student, Almost normal Guy
>
> http://www.google.com/profiles/ulrich.moritz

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