transient-0.6.0.1: composing programs with multithreading, events and distributed computing

Safe HaskellNone
LanguageHaskell2010

Transient.Logged

Contents

Description

The logged primitive is used to save the results of the subcomputations of a transient computation (including all its threads) in a log buffer. At any point, a suspend or checkpoint can be used to save the accumulated log on a persistent storage. A restore reads the saved logs and resumes the computation from the saved checkpoint. On resumption, the saved results are used for the computations which have already been performed. The log contains purely application level state, and is therefore independent of the underlying machine architecture. The saved logs can be sent across the wire to another machine and the computation can then be resumed on that machine. We can also save the log to gather diagnostic information, especially in finish blocks.

The following example illustrates the APIs. In its first run suspend saves the state in a directory named logs and exits, in the second run it resumes from that point and then stops at the checkpoint, in the third run it resumes from the checkpoint and then finishes.

main= keep $ restore  $ do
     r <- logged $ choose [1..10 :: Int]
     logged $ liftIO $ print ("A",r)
     suspend ()
     logged $ liftIO $ print ("B",r)
     checkpoint
     liftIO $ print ("C",r)

Synopsis

Documentation

type Loggable a = (Show a, Read a, Typeable a) Source #

Constraint type synonym for a value that can be logged.

logged :: Loggable a => TransIO a -> TransIO a Source #

Run the computation, write its result in a log in the parent computation and return the result. If the log already contains the result of this computation (restored from previous saved state) then that result is used instead of running the computation again.

logged can be used for computations inside a logged computation. Once the parent computation is finished its internal (subcomputation) logs are discarded.

received :: Loggable a => a -> TransIO () Source #

suspend :: Typeable a => a -> TransIO a Source #

Saves the logged state of the current computation that has been accumulated using logged, and then exits using the passed parameter as the exit code. Note that all the computations before a suspend must be logged to have a consistent log state. The logs are saved in the logs subdirectory of the current directory. Each thread's log is saved in a separate file.

checkpoint :: TransIO () Source #

Saves the accumulated logs of the current computation, like suspend, but does not exit.

restore :: TransIO a -> TransIO a Source #

Reads the saved logs from the logs subdirectory of the current directory, restores the state of the computation from the logs, and runs the computation. The log files are removed after the state has been restored.

low level

toIDyn :: (Typeable * a, Read a, Show a) => a -> IDynamic Source #