timeout-with-results-0.2: Runs a time-limited computation alowing it to return intermediate results.

Safe HaskellSafe-Inferred

System.Timeout.Returning

Description

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."

Synopsis

Documentation

class Monad m => MonadTimeout w m | m -> w whereSource

Monad for computations that can save partial results of type w during their evaluation.

Methods

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.

yield :: m ()Source

Explicitly allow interrupting the computation at this point. Experimental.

data Timeout w a Source

An IO-based implementation of MonadTimeout. Calling partialResult replaces any previously written value with the new one.

runTimeoutNFSource

Arguments

:: NFData w 
=> Int

TimeoutWriter in microseconds.

-> Timeout w (Maybe w)

The computation.

-> IO (Maybe w)

The result, or Nothing if no value was returned.

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.

runTimeoutWHNFSource

Arguments

:: Int

TimeoutWriter in microseconds.

-> Timeout w (Maybe w)

The computation.

-> IO (Maybe w)

The result, or Nothing if no value was returned.

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.