What it means is if you have nested actions, e.g.

    (def a (agent 0))
    (def b (agent 0))

    (send a (fn [x] (send b inc) (inc x)))

So under normal circumstances, the inner send is placed on a queue until
the value of a is changed. This means we can guarantee that a will change
before b.

If we want to override this behaviour, you can use release-pending-sends

    (send a (fn [x] (send b inc) (release-pending-sends) (inc x)))

The above code will send to b *before* the send to a completes (unless I've
completely misunderstood!)

- James

On 31 May 2015 at 20:29, <lawre...@waleup.com> wrote:

> I am looking here:
>
> http://clojuredocs.org/clojure.core/release-pending-sends
>
> It says:
>
> Normally, actions sent directly or indirectly during another action
> are held until the action completes (changes the agent's
> state). This function can be used to dispatch any pending sent
> actions immediately. This has no impact on actions sent during a
> transaction, which are still held until commit. If no action is
> occurring, does nothing. Returns the number of actions dispatched.
>
>
> I can not figure out what this means. This function takes no arguments? I
> see it defined like this:
>
> (release-pending-sends)
>
> So I can not call it on a specific agent, instead, this function is global
> in its effects? It effects every agent in my app? Or perhaps I am suppose
> to call it from inside the agent, and it only dismisses the functions that
> have piled up on that agents queue?
>
> If I do this:
>
> (def users (agent {}))
> (def contests (agent {}))
> (send users calculate-winnings-per-category)
> (send users calculate-winnings-total)
> (send users remove-the-losers)
> (send contests generate-new-contests)
> (send contests assign-prize-money)
>
> (release-pending-sends)
>
> What happens? The agent starts on whatever function happens to be put into
> its queue first, and it continues with the execution of that function, but
> all the other sends are cancelled?
>
> Also, is there a way to see how many functions are pending for an agent?
>
>
>
>
>
>
>
>
>
>
>  --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to