HAppS-Util-0.9.2: Web framework

Portabilityuses mdo



Timeout implementation for performing operations in the IO monad with a timeout added. Both using Maybe and exceptions to handle timeouts are supported.

Timeouts can be implemented in GHC with either a global handler or a per-timeout thread which sleeps until the timeout. The latter is used in this module. Blocking on foreign calls can cause problems as GHC has no way of interrupting such threads. The module provides a slightly slower alternative implementation which returns even if the computation has blocked on a foreign call. This should not be an issue unless -threaded is used.

The timeouts are currently limited to a maximum of about 2000 seconds. This is a feature of threadDelay, but supporting longer timeouts is certainly possible if that is desirable.



withTimeOut :: Int -> IO a -> IO aSource

This is the normal timeout handler. It throws a dynamic exception (TimeOutException), if the timeout occurs.

withTimeOutMaybe :: Int -> IO a -> IO (Maybe a)Source

This is the normal timeout handler. If the computation fails or the timeout is reached it returns Nothing.

withSafeTimeOut :: Int -> IO a -> IO aSource

Like timeOut, but additionally it works even if the computation is blocking async exceptions (explicitely or by a blocking FFI call). This consumes more resources than timeOut, but is still quite fast.

withSafeTimeOutMaybe :: Int -> IO a -> IO (Maybe a)Source

Like withTimeOutMaybe, but handles the operation blocking exceptions like withSafeTimeOut does.

second :: IntSource

Constant representing one second.