on develop help sign in
Reflex.Time: add tickLossyFromPostBuildTime
9cc8f7bKen Micklas
src/Reflex/Time.hs+12−1
@@ -7,6 +7,7 @@
7#ifdef USE_TEMPLATE_HASKELL
7#ifdef USE_TEMPLATE_HASKELL
8{-# LANGUAGE TemplateHaskell #-}
8{-# LANGUAGE TemplateHaskell #-}
9#endif
9#endif
10+{-# LANGUAGE TupleSections #-}
10{-# LANGUAGE TypeFamilies #-}
11{-# LANGUAGE TypeFamilies #-}
11module Reflex.Time where
12module Reflex.Time where
12
13
@@ -41,18 +42,28 @@ data TickInfo
41 }
42 }
42 deriving (Eq, Ord, Show, Typeable)
43 deriving (Eq, Ord, Show, Typeable)
43
44
44−-- | Special case of tickLossyFrom that uses the post-build event to start the
45+-- | Special case of 'tickLossyFrom' that uses the post-build event to start the
45-- tick thread.
46-- tick thread.
46tickLossy :: (PostBuild t m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m) => NominalDiffTime -> UTCTime -> m (Event t TickInfo)
47tickLossy :: (PostBuild t m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m) => NominalDiffTime -> UTCTime -> m (Event t TickInfo)
47tickLossy dt t0 = tickLossyFrom dt t0 =<< getPostBuild
48tickLossy dt t0 = tickLossyFrom dt t0 =<< getPostBuild
48
49
50+-- | Special case of 'tickLossyFrom' that uses the post-build event to start the
51+-- tick thread and the time of the post-build as the tick basis time.
52+tickLossyFromPostBuildTime :: (PostBuild t m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m) => NominalDiffTime -> m (Event t TickInfo)
53+tickLossyFromPostBuildTime dt = do
54+ postBuild <- getPostBuild
55+ postBuildTime <- performEvent $ liftIO getCurrentTime <$ postBuild
56+ tickLossyFrom' $ (dt,) <$> postBuildTime
57+
49-- | Send events over time with the given basis time and interval
58-- | Send events over time with the given basis time and interval
50-- If the system starts running behind, occurrences will be dropped rather than buffered
59-- If the system starts running behind, occurrences will be dropped rather than buffered
51-- Each occurrence of the resulting event will contain the index of the current interval, with 0 representing the basis time
60-- Each occurrence of the resulting event will contain the index of the current interval, with 0 representing the basis time
52tickLossyFrom
61tickLossyFrom
53 :: (PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m)
62 :: (PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m)
54 => NominalDiffTime
63 => NominalDiffTime
64+ -- ^ The length of a tick interval
55 -> UTCTime
65 -> UTCTime
66+ -- ^ The basis time from which intervals count
56 -> Event t a
67 -> Event t a
57 -- ^ Event that starts a tick generation thread. Usually you want this to
68 -- ^ Event that starts a tick generation thread. Usually you want this to
58 -- be something like the result of getPostBuild that only fires once. But
69 -- be something like the result of getPostBuild that only fires once. But