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:
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.
A darcs repository is available. The darcs command is:
darcs get http://common-lisp.net/project/trivial-timeout/
trivial-timeout is also ASDF installable. Its CLiki home is right where you'd expect.
There's also a handy gzipped tar file.
10 Sept 2008 - Separated trivial-timeout from lift and trivial-shell. There was much rejoicing.