Sounds good to me. The first version of that function I wrote without returning nil, but just bubbling up the exception. I changed it because I couldn't think of another area of the Clojure core that threw an exception like that. Looking through some of the agents code, I think there are some similar scenarios that do throw an exception.
As far as the seconds/minutes etc stuff. I just added that to not lose anything from the Java API. Getting rid of that, the much simpler function looks like: (defn future-await "Returns the value of the future just like a deref. If the future has not completed by timeout, nil is returned" [^java.util.concurrent.Future f timeout-in-millis] (.get f timeout-in-millis java.util.concurrent.TimeUnit/MILLISECONDS)) Usage is same as before: (def fut (future (Thread/sleep 10000) "done")) (future-await fut 1) ; throws java.util.concurrent.TimeoutException (def fut (future (Thread/sleep 10000) "done")) (future-await fut 100000) ; "done" -Ryan On Sat, Jun 26, 2010 at 12:56 AM, Meikel Brandmeyer <m...@kotka.de> wrote: > Hi, > > Am 25.06.2010 um 20:48 schrieb Daniel Werner: > > > On 25 June 2010 05:27, Ryan Senior <senior.r...@gmail.com> wrote: > >> (future-await fut2 2 :minutes) ; => "done" > > > > What do others think? > > I agree – in particular for point 2. > > For point 1: I think "2 :minutes" is not very clojure-like. It sound more > like Ruby: 2.minutes. A more clojure-like approach would be to an use > optional keyword argument. > > (defn future-await > [fut & {:keys [timeout]}] > ....) > > (future-await zukunft) > (future-await zukunft :timeout time-out-in-ms) > > Or of course the simple two-arg-version. > > Sincerely > Meikel > > -- > 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<clojure%2bunsubscr...@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 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