rhine-1.4: Functional Reactive Programming with type-level clocks
Safe HaskellSafe-Inferred
LanguageHaskell2010

FRP.Rhine.Clock.Realtime

Synopsis

Documentation

type UTCClock m cl = RescaledClockS m cl UTCTime (Tag cl) Source #

A clock rescaled to the UTCTime time domain.

There are different strategies how a clock may be rescaled, see below.

overwriteUTC :: MonadIO m => cl -> UTCClock m cl Source #

Rescale an IO clock to the UTC time domain, overwriting its timestamps.

addUTC :: (Real (Time cl), MonadIO m) => cl -> UTCClock m cl Source #

Rescale a clock to the UTC time domain.

The initial time stamp is measured as system time, and the increments (durations between ticks) are taken from the original clock. No attempt at waiting until the specified time is made, the timestamps of the original clock are trusted unconditionally.

type WaitUTCClock m cl = RescaledClockS m cl UTCTime (Tag cl, Maybe (Diff (Time cl))) Source #

Like UTCClock, but also output in the tag whether and by how much the target realtime was missed.

The original clock specifies with its time stamps when, relative to the initialisation time, the UTC clock should tick. A tag of (tag, Nothing) means that the tick was in time. (tag, Just dt) means that the tick was too late by dt.

waitUTC :: (Real (Time cl), MonadIO m, Fractional (Diff (Time cl))) => cl -> WaitUTCClock m cl Source #

Measure the time after each tick, and wait for the remaining time until the next tick.

If the next tick should already have occurred dt seconds ago, the tag is set to Just dt, representing a failed real time attempt.

Note that this clock internally uses threadDelay which can block for quite a lot longer than the requested time, which can cause waitUTC to miss one or more ticks when using a fast original clock. When using threadDelay, the difference between the real wait time and the requested wait time will be larger when using the -threaded ghc option (around 800 microseconds) than when not using this option (around 100 microseconds). For fast clocks it is recommended that -threaded not be used in order to miss less ticks. The clock will adjust the wait time, up to no wait time at all, to catch up when a tick is missed.