@Moe
thanks for your explanation ,finally understand the author¹s point.
Best regards
From: <[email protected]> on behalf of Moe Aboulkheir
<[email protected]>
Reply-To: <[email protected]>
Date: Wednesday, September 9, 2015 at 1:22 AM
To: <[email protected]>
Subject: Re: book [clojure programming] confuse
> Johnny,
>
> On Tue, Sep 8, 2015 at 11:32 AM, Johnny Wong <[email protected]> wrote:
>> why " deliver a @b is going to fail " ? 1 and 2 are just two independent
>> threads , "deliver a 42" will unblock thread 2 , and then thread 1 will be
>> unblocked .
>
> Thread 1 is waiting on delivering a result to "a", though, which has already
> happened with the outer (deliver a 42) - one result per promise.
>> what is the pointer of function sync-fn ? what is the execution sequence of
>> functions such as sync-fn,call-servervice, and callback-fn ? statement
>> "((sync-fn call-service) 8 7) ", where is the callback-fn parameter ?
>
> After the apply, call-service ends up being invoked as (call-service 8 7
> #(deliver result %&)) - the callback-fn is that final anonymous function which
> delivers the "result" promise a sequence of its arguments (%&). sync-fn is
> geared towards multiple invocations - a named example may be very slightly
> clearer:
>
> (def call-service-sync (sync-fn call-service))
> (call-service-sync 8 7) ;; => (15 1)
>
> The sequence is:
> - Invoke (sync-fn call-service), which returns a wrapper around call-service,
> using a callback-fn which is internal to the wrapper (consumers of sync-fn are
> trying to ignore callback-fn)
> - Invoke the returned function/wrapper with the arguments to the wrapped
> (call-service) function (8 7), minus callback-fn
> - The wrapper forwards these arguments to call-service, plus a callback-fn
> which delivers its arguments to a promise
> - The wrapper blocks on dereferencing the promise
> - The outermost caller receives the value delivered to the promise
>
> Take care,
> Moe
> --
> 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
> ---
> You received this message because you are subscribed to a topic in the Google
> Groups "Clojure" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/clojure/C92OCoEXjCo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> 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 [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
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.