Safe Haskell | Safe-Inferred |
---|
Defines a simple monad for computations that can be interrupted by a timeout, and save partial results before that.
If you need a more powerful mechanism, where you can retrieve and combine previously saved partial results, use module System.Timeout.Returning.Writer.
Mind that (from documentation of throwTo
): "There
is no guarantee that the exception will be delivered promptly, although
the runtime will endeavour to ensure that arbitrary delays don't occur. In
GHC, an exception can only be raised when a thread reaches a safe point,
where a safe point is where memory allocation occurs. Some loops do not
perform any memory allocation inside the loop and therefore cannot be
interrupted by a throwTo
."
- class Monad m => MonadTimeout w m | m -> w where
- partialResult :: w -> m ()
- yield :: m ()
- data Timeout w a
- runTimeoutNF :: NFData w => Int -> Timeout w (Maybe w) -> IO (Maybe w)
- runTimeoutWHNF :: Int -> Timeout w (Maybe w) -> IO (Maybe w)
Documentation
class Monad m => MonadTimeout w m | m -> w whereSource
Monad for computations that can save partial results
of type w
during their evaluation.
partialResult :: w -> m ()Source
Store a new partial result. The precise semantics of what happens with the written value is by intent unspecified and left to be decided by implementations.
Explicitly allow interrupting the computation at this point. Experimental.
(Monad (TimeoutWriter w), Monoid w) => MonadTimeout w (TimeoutWriter w) | |
Monad (Timeout w) => MonadTimeout w (Timeout w) |
An IO
-based implementation of MonadTimeout
.
Calling partialResult
replaces any previously written value
with the new one.
:: NFData w | |
=> Int | TimeoutWriter in microseconds. |
-> Timeout w (Maybe w) | The computation. |
-> IO (Maybe w) | The result, or |
Runs the given simple computation with the given timeout. If the
computation returns a value, the value is returned. If it doesn't or
times out, the last partial result written by partialResult
is returned.
Each partial result is converted to normal form prior being saved.
:: Int | TimeoutWriter in microseconds. |
-> Timeout w (Maybe w) | The computation. |
-> IO (Maybe w) | The result, or |
Runs the given simple computation with the given timeout. If the
computation returns a value, the value is returned. If it doesn't or
times out, the last partial result written by partialResult
is returned.
Each partial result is converted to weak head normal form prior being
saved.