Time out

Koen Claessen koen@cs.chalmers.se
Tue, 10 Sep 2002 12:03:32 +0200 (MET DST)


Hi all,

What is the recommended way of implementing the function:

  timeOut :: Int -> IO a -> IO (Maybe a)

which takes a maximum number of seconds (say), an IO action,
and tries to run the IO action in the specified time. If it
succeeds, it returns just the answer, otherwise it returns
Nothing.

Do I have to start two threads, one that waits and then
throws an exception, the other that evaluates the IO action?

Or is there a better way? (I thought of asynchronous
exceptions...)

/Koen.

--
Koen Claessen
http://www.cs.chalmers.se/~koen
Chalmers University, Gothenburg, Sweden.