In Overtone we have the same situation, where we return a promise representing a server response and sometimes we want to timeout if the response never arrives. This is what we use:
(defn await-promise! ([prom] (await-promise prom REPLY-TIMEOUT)) ([prom timeout] (.get (future @prom) timeout TimeUnit/MILLISECONDS))) (We have another version without the exclamation mark that returns :timeout rather than throwing an exception when timed out.) I agree with you though, that something along these lines should be built-in. I was surprised to find that there was no way to block on a promise with a timeout, as it seems like such a typical requirement for almost anything you might be promised. -Jeff On Mar 9, 1:12 pm, Sean Allen <s...@monkeysnatchbanana.com> wrote: > Yesterday I was writing a bit of code that needs to wait for an > external event to happen but if it doesn't happen with X amount of > time, > to timeout with an error. > > Is there a library to handle this? I know you can do it with a future > and if you google the general idea, there are a few blog posts, stack > overflow questions etc that all have the same basic solution. It seems > like such a common thing to do that there would be a standard > function/macro out there for it rather than everyone rolling their > own. I couldn't however find one. > > Does one exist? If yes, pointer in the right direction. > > Thanks, > Sean -- 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