On Thu, Jan 21, 2010 at 6:19 AM, Baishampayan Ghose
<b.gh...@ocricket.com> wrote:
>
> It would be great if someone pointed out some example usage of 
> promise/deliver.

I've used them to convert a callback-based (continuation-passing
style, if you will) API into a blocking one.  The lib I was using
provides something you can call like:

        (rpc-call destination method-args done)

Where 'done' is a function that gets called with the results of
the remote procedure call.  But I want to write a function that
does rpc but *returns* the result, so...

        (let [p (promise)]
          (rpc-call destination method-args #(deliver p %))
          @p)

This will work just fine whether rpc-call calls 'done'
synchronously, or if it returns right away and 'done' is called
by some other thread later.

--Chouser
http://joyofclojure.com/

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