| Copyright | (c) Nils Anders Danielsson 2004-2021 |
|---|---|
| License | See the file LICENCE. |
| Maintainer | http://www.cse.chalmers.se/~nad/ |
| Stability | experimental |
| Portability | non-portable (preemptive scheduling) |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Test.ChasingBottoms.TimeOut
Description
When dealing with "hard bottoms", i.e. non-terminating computations that do not result in exceptions, the following functions may be handy.
Note that a computation is considered to have terminated when it has reached weak head normal form (i.e. something distinct from bottom).
Documentation
Constructors
| Value a | |
| NonTermination | |
| Exception SomeException |
timeOut :: Int -> IO a -> IO (Result a) Source #
runs timeOut n cc for at most n seconds (modulo
scheduling issues).
- If the computation terminates before that, then
is returned, whereValuevvis the resulting value. Note that this value may be equal to bottom, e.g. ifc =.returnbottom - If the computation does not terminate, then
NonTerminationis returned. - If the computation raises an exception, then
is returned, whereExceptioneeis the exception.
Note that a user-defined exception is used to terminate the
computation, so if c catches all exceptions, or blocks
asynchronous exceptions, then timeOut may fail to function
properly.
timeOut' :: Int -> a -> IO (Result a) Source #
timeOut' is a variant which can be used for pure
computations. The definition,
timeOut'n =timeOutn .evaluate
ensures that usually returns timeOut' 1 bottom. (Exception
<something> usually
returns timeOut 1 (return bottom); in other words, the computation
reaches whnf almost immediately, defeating the purpose of the
time-out.)Value bottom
timeOutMicro :: Int -> IO a -> IO (Result a) Source #
timeOutMicro takes a delay in microseconds. Note that the
resolution is not necessarily very high (the last time I checked it
was 0.02 seconds when using the standard runtime system settings
for GHC).
timeOutMicro' :: Int -> a -> IO (Result a) Source #
timeOutMicro' is the equivalent variant of timeOutMicro:
timeOutMicro'n =timeOutMicron .evaluate