Move rate test to examples

This commit is contained in:
Harendra Kumar 2020-06-03 19:37:12 +05:30
parent 48b21f731b
commit 1691aa3ed1
3 changed files with 23 additions and 26 deletions

11
examples/Rate.hs Normal file
View File

@ -0,0 +1,11 @@
import Streamly
import qualified Streamly.Prelude as S
import qualified Streamly.Internal.Prelude as Internal
main :: IO ()
main =
S.mapM_ print
$ asyncly
$ avgRate 1
$ Internal.timestamped
$ S.repeatM (pure "tick")

View File

@ -864,3 +864,15 @@ executable CamelCase
, base >= 4.8 && < 5
else
buildable: False
executable Rate
import: exe-options
main-is: Rate.hs
hs-source-dirs: examples
if (flag(examples) || flag(examples-sdl)) && !impl(ghcjs)
buildable: True
build-Depends:
streamly
, base >= 4.8 && < 5
else
buildable: False

View File

@ -1,26 +0,0 @@
{-# LANGUAGE FlexibleContexts #-}
import Streamly
import Streamly.Prelude as S
import Control.Monad (when)
import Control.Monad.IO.Class (MonadIO(liftIO))
import System.Clock
withTimeStamp msg = do
t <- getTime Monotonic
let ns = toNanoSecs t `mod` 10^11
putStrLn $ show (fromIntegral ns / 1.0e9) <> " " <> msg
-- acidRain :: MonadAsync m => SerialT m Event
producer =
asyncly
$ avgRate 1
$ S.repeatM
$ liftIO $ do
withTimeStamp "produced"
return 1
main :: IO ()
main = runStream $ do
_ <- producer
liftIO $ withTimeStamp "consumed\n"