ModuleChasingBottoms-1.3.1.16Haskell2010
Test.ChasingBottoms.TimeOut
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).
- 1 type
- 4 values
- PackageChasingBottoms-1.3.1.16
- Exports5
- LanguageHaskell2010
- LicenceMIT
- SourceTimeOut.hs
timeOut n c runs c for at most n seconds (modulo
scheduling issues).
If the computation terminates before that, then
Value vis returned, wherevis the resulting value. Note that this value may be equal to bottom, e.g. ifc = return bottom.If the computation does not terminate, then NonTermination is returned.
If the computation raises an exception, then
Exception eis returned, whereeis 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' is a variant which can be used for pure computations. The definition,
timeOut' n = timeOut n . evaluate
ensures that timeOut' 1 bottom usually returns Exception
<something>. (timeOut 1 (return bottom) usually
returns Value bottom; in other words, the computation
reaches whnf almost immediately, defeating the purpose of the
time-out.)
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' is the equivalent variant of timeOutMicro:
timeOutMicro' n = timeOutMicro n . evaluate