module Test.Framework.Runners.TimedConsumption (
consumeListInInterval
) where
import Test.Framework.Utilities
import System.CPUTime ( getCPUTime )
consumeListInInterval :: Int -> [a] -> IO [a]
consumeListInInterval :: forall a. Int -> [a] -> IO [a]
consumeListInInterval Int
delay [a]
list = do
initial_time_ps <- IO Integer
getCPUTime
go initial_time_ps (microsecondsToPicoseconds (fromIntegral delay)) list
where
go :: Integer -> Integer -> [a] -> IO [a]
go Integer
_ Integer
_ [] = [a] -> IO [a]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
go Integer
initial_time_ps Integer
delay_ps (a
x:[a]
xs) = do
this_time <- IO Integer
getCPUTime
if this_time - initial_time_ps < delay_ps
then go initial_time_ps delay_ps xs >>= return . (x:)
else return []