Johnny,

On Tue, Sep 8, 2015 at 11:32 AM, Johnny Wong <zhanlandet...@gmail.com>
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 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