@@ -7,6 +7,7 @@
77#ifdef USE_TEMPLATE_HASKELL
88{-# LANGUAGE TemplateHaskell #-}
99#endif
10+{-# LANGUAGE TupleSections #-}
1011{-# LANGUAGE TypeFamilies #-}
1112module Reflex.Time where
1213
@@ -41,18 +42,28 @@ data TickInfo
4142 }
4243 deriving (Eq, Ord, Show, Typeable)
4344
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
4546-- tick thread.
4647tickLossy :: (PostBuild t m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m) => NominalDiffTime -> UTCTime -> m (Event t TickInfo)
4748tickLossy dt t0 = tickLossyFrom dt t0 =<< getPostBuild
4849
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+
4958-- | Send events over time with the given basis time and interval
5059-- If the system starts running behind, occurrences will be dropped rather than buffered
5160-- Each occurrence of the resulting event will contain the index of the current interval, with 0 representing the basis time
5261tickLossyFrom
5362 :: (PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m)
5463 => NominalDiffTime
64+ -- ^ The length of a tick interval
5565 -> UTCTime
66+ -- ^ The basis time from which intervals count
5667 -> Event t a
5768 -- ^ Event that starts a tick generation thread. Usually you want this to
5869 -- be something like the result of getPostBuild that only fires once. But