In Joy of Clojure, there is a callback API to blocking API example in the section on promises. Chouser outlines it a briefly in a discussion on Promise/Deliver use cases here - http://groups.google.com/group/clojure/browse_thread/thread/b1548aa40ba8072/210ec81bfe26032e?lnk=gst&q=promise#210ec81bfe26032e:
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 This is very neat. Is this robust as is or would you need to add code to handle error cases such as an unavailable rpc server, rpc server never returning, an error trying to make the rpc call, etc. -- 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