time-warp-1.1.1.2: Distributed systems execution emulation

Copyright(c) Serokell 2016
LicenseGPL-3 (see the file LICENSE)
MaintainerSerokell <hi@serokell.io>
Stabilityexperimental
PortabilityPOSIX, GHC
Safe HaskellNone
LanguageHaskell2010

Control.TimeWarp.Timed

Description

This module provides time- and thread-management capabilities. It allows to write scenarios over multithreaded systems, which can then be launched as either real program or emulation with no need to wait for delays.

Example:

example :: MonadTimed m => m ()
example = do
    schedule (at 10 minute) $ do
        time <- toMicroseconds <$> virtualTime
        liftIO $ putStrLn $ "Hello! It's " ++ show time ++ " now"
    wait (for 9 minute)
    liftIO $ putStrLn "One more minute..."

Such scenario can be launched in real mode using

>>> runTimedIO example
<9 minutes passed>
One more minute...
<1 more minute passed>
Hello! It's 600000000µs now

and like emulation via

>>> runTimedT example
One more minute...
Hello! It's 600000000µs now

which works on the spot.

Documentation