| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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
- type Loggable a = (Show a, Read a, Typeable a)
- logged :: Loggable a => TransIO a -> TransIO a
- received :: Loggable a => a -> TransIO ()
- param :: Loggable a => TransIO a
- suspend :: Typeable a => a -> TransIO a
- checkpoint :: TransIO ()
- restore :: TransIO a -> TransIO a
- fromIDyn :: Loggable a => IDynamic -> a
- maybeFromIDyn :: Loggable a => IDynamic -> Maybe a
- toIDyn :: (Show a, Read a, Typeable a) => a -> IDynamic
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.
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.