mock-time-0.1.0: Mock time in tests
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.SimulatedTime

Description

Contains a simulated-time implementaion. It can be used directly, to implement the simulated versions of getCurrentTime and threadDelay, or can be used via monad transformers defined in SimulatedTime

Synopsis

Documentation

data TimeEnv Source #

It remembers the offset from system time and keeps a list of sleeping threads (threads in threadDelay' call)

create :: UTCTime -> IO TimeEnv Source #

Create the simulated time env from the given time start point. For example

timeEnv <- create (fromGregorian 2000 1 1) 0
getSimulatedTime timeEnv

advance :: TimeEnv -> NominalDiffTime -> IO () Source #

Move the simulated time by a delta

triggerEvents :: TimeEnv -> IO () Source #

Wake up due sleeping threads, based on TimeEnv. This happens on its own, but this call can quicken things up. Under the hood it is just advance tenv 0

getSimulatedTime :: TimeEnv -> IO UTCTime Source #

The current simulated time

threadDelay' :: TimeEnv -> Int -> IO () Source #

Simulated alternative to threadDelay, sleep for the given number of microseconds. Threads wakes up according to the simulated time.