See https://github.com/Raynes/clojail

It's a sandboxing library for Clojure, which among other things means
it needs to try running an operation and give up after N seconds. You
can skip the sandboxing part entirely if you want; it exposes a pretty
general thunk-timeout function.

On Mar 9, 4:43 am, Sean Allen <s...@monkeysnatchbanana.com> wrote:
> On Wed, Mar 9, 2011 at 7:25 AM, Baishampayan Ghose <b.gh...@gmail.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.
>
> > You can roll your own macro to do this.
>
> > Example -
>
> > (defmacro with-timeout [ms & body]
> >  `(let [f# (future ~@body)]
> >    (.get #^java.util.concurrent.Future f# ~ms
> > java.util.concurrent.TimeUnit/MILLISECONDS)))
>
> Variation on that macro are what I've seen across the variety of sources
> I've mentioned in my original message. It just strikes me as odd that 
> something
> so general hasn't made it into a library.
>
> If it really hasn't made a library, ok.. I just wanted to make sure it
> wasn't in a
> library somewhere and that keeping the hand rolled macro wasn't something
> I should still be doing.

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