on develop help sign in
define homogeneous poisson as inhomogeneous poisson with constant rate (remove some duplicate code)
commitbea6bed429648a2bed939b44fca7b4bb32c26502 authorGreg Hale <imalsogreg@gmail.com> dateSat 16 May 2015, 18:57 (11 years ago) parent2c128d2
1 file changed+2−11
src/Reflex/Dom/Time.hs+2−11
src/Reflex/Dom/Time.hs+2−11
@@ -69,17 +69,8 @@ poissonLossyFrom
6969 -- there could be uses for starting multiple timer threads.
7070 -- Start sending events in response to the event parameter.
7171 -> m (Event t TickInfo)
72−poissonLossyFrom rnd rate t0 e = performEventAsync $ fmap callAtNextInterval e
73− where callAtNextInterval _ cb = void $ liftIO $ forkIO $ go rnd cb
74− go lastGen cb = do
75− t <- getCurrentTime
76− let (u, nextGen) = randomR (0,1) lastGen
77− dt = realToFrac $ -1 * log(u)/rate :: NominalDiffTime
78− offset = t `diffUTCTime` t0
79− (n, alreadyElapsed) = offset `divMod'` dt
80− threadDelay $ ceiling $ (dt - alreadyElapsed) * 1000000
81− void $ cb $ TickInfo t n alreadyElapsed
82− go nextGen cb
72+poissonLossyFrom rnd rate t0 t =
73+ inhomogeneousPoissonFrom rnd (current $ constDyn rate) rate t0 t
8374
8475
8576-- | Send events with Poisson timing with the given basis and rate