What it is

Sometimes you don't have the time to wait.

Although most Lisps have a mechanism to write code that says "do this for 5 seconds and give up if you're not done", they didn't agree on exactly what that mechanism should look like. Trivial-timeout steps into the gap with a platform independent syntax for timeouts. You use it like this:

(with-timeout (duration)  
  (run-some-long-running-code)) 

If duration (a time in seconds) is exceeded, then a timeout-error will be signaled. A more idiomatic example would probably be:

(handler-case  
  (with-timeout (60)  
    (make-microwave-popcorn))  
  (timeout-error (c)  
    (declare (ignore c))  
    (print "I wanted to make popcorn, but who has the time these days"))) 

Here's the full skinny:

with-timeout (seconds) &body body
macro

Execute body for no more than seconds time.

If seconds is exceeded, then a timeout-error will be signaled.

If seconds is nil, then the body will be run normally until it completes or is interrupted.

timeout-error
condition
An error signaled when the duration specified in the with-timeout is exceeded.

Where is it

the current trivial-timeout repository is on github and you can clone it using:

git clone git://github.com/gwkkwg/trivial-timeout  
 

What is happening

5 Jan 2013 - Just cleanup, nothing exciting happening here.

10 Sept 2008 - Separated trivial-timeout from lift and trivial-shell. There was much rejoicing.