on develop help sign in
define homogeneous poisson as inhomogeneous poisson with constant rate (remove some duplicate code)
bea6bedGreg Hale
src/Reflex/Dom/Time.hs+2−11
@@ -69,17 +69,8 @@ poissonLossyFrom
69 -- there could be uses for starting multiple timer threads.
69 -- there could be uses for starting multiple timer threads.
70 -- Start sending events in response to the event parameter.
70 -- Start sending events in response to the event parameter.
71 -> m (Event t TickInfo)
71 -> m (Event t TickInfo)
72−poissonLossyFrom rnd rate t0 e = performEventAsync $ fmap callAtNextInterval e
72+poissonLossyFrom rnd rate t0 t =
73− where callAtNextInterval _ cb = void $ liftIO $ forkIO $ go rnd cb
73+ inhomogeneousPoissonFrom rnd (current $ constDyn rate) rate t0 t
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
83
74
84
75
85-- | Send events with Poisson timing with the given basis and rate
76-- | Send events with Poisson timing with the given basis and rate