box-0.9.3.1: A profunctor effect system.
Safe HaskellSafe-Inferred
LanguageGHC2021

Box.Time

Description

Timing effects.

Synopsis

Documentation

sleep :: Double -> IO () Source #

Sleep for x seconds.

stampNow :: a -> IO (LocalTime, a) Source #

Add the current time

stampE :: Emitter IO a -> Emitter IO (LocalTime, a) Source #

Add the current time stamp.

> toListM . stampE $| (qList [1..3])
[(2022-08-30 01:55:16.517127,1),(2022-08-30 01:55:16.517132,2),(2022-08-30 01:55:16.517135,3)]

type Gap = Double Source #

Usually represents seconds.

gaps :: Emitter IO (LocalTime, a) -> CoEmitter IO (Gap, a) Source #

Convert stamped emitter to gap between emits in seconds

toListM <$|> (gaps =<< (fromGapsNow =<< (qList (zip (0:repeat 1) [1..4]))))
[(0.0,1),(1.0,2),(1.0,3),(1.0,4)]

fromGaps :: LocalTime -> Emitter IO (Gap, a) -> CoEmitter IO (LocalTime, a) Source #

Convert gaps in seconds to stamps starting from an initial supplied LocalTime

fromGapsNow :: Emitter IO (Gap, a) -> CoEmitter IO (LocalTime, a) Source #

Convert gaps in seconds to stamps starting with current time

toListM <$|> (fromGapsNow =<< (qList (zip (0:repeat 1) [1..4])))
[(2022-08-30 22:57:33.835228,1),(2022-08-30 22:57:34.835228,2),(2022-08-30 22:57:35.835228,3),(2022-08-30 22:57:36.835228,4)]

gapEffect :: Emitter IO (Gap, a) -> Emitter IO a Source #

Convert a (Gap,a) emitter to an a emitter, with delays between emits of the gap.

skip :: Int -> Emitter IO (Gap, a) -> CoEmitter IO (Gap, a) Source #

Ignore the first n gaps and immediately emit them.

replay :: Double -> Int -> Emitter IO (LocalTime, a) -> CoEmitter IO a Source #

Replay a stamped emitter, adjusting the speed of the replay.

toListM . stampE <$|> (replay 0.1 1 =<< (fromGapsNow =<< (qList (zip (0:repeat 1) [1..4]))))
[(2022-08-31 02:29:39.643831,1),(2022-08-31 02:29:39.643841,2),(2022-08-31 02:29:39.746998,3),(2022-08-31 02:29:39.849615,4)]

gapSkipEffect :: Emitter IO Int -> Emitter IO Gap -> CoEmitter IO Gap Source #

Only add a Gap effect if greater than the Int emitter

effect is similar to a fast-forward of the first n emits

speedEffect :: Emitter IO Gap -> Emitter IO (Gap, a) -> Emitter IO a Source #

Using the Gap emitter, adjust the Gap for a (Gap, a) emitter

speedSkipEffect :: Emitter IO (Int, Gap) -> Emitter IO (Gap, a) -> CoEmitter IO a Source #

Only add a Gap if greater than the Int emitter

effect is similar to a fast-forward of the first n emits