mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 11:37:22 +03:00
More complicated logging tests
This commit is contained in:
parent
760a298598
commit
afbd289a89
13
test/3-waitEvents.hs
Normal file
13
test/3-waitEvents.hs
Normal file
@ -0,0 +1,13 @@
|
||||
import Control.Concurrent (threadDelay, myThreadId)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import System.Random (randomIO)
|
||||
import System.IO
|
||||
|
||||
import Strands
|
||||
|
||||
--- Check space leaks
|
||||
|
||||
main = wait_ $ do
|
||||
x <- waitEvents (randomIO :: IO Int)
|
||||
y <- waitEvents (randomIO :: IO Int)
|
||||
return (x, y)
|
@ -1,26 +1,35 @@
|
||||
import Strands
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
|
||||
import Control.Applicative ((<$>), (<*>), (<|>))
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import System.IO
|
||||
import Strands
|
||||
|
||||
main = do
|
||||
logs <- waitLogged comp
|
||||
hSetBuffering stdout LineBuffering
|
||||
logs <- waitLogged_ comp
|
||||
|
||||
putStrLn $ "\nResuming with logs:"
|
||||
logs1 <- waitLogged $ eachWithLog comp logs
|
||||
logs1 <- waitLogged_ $ eachWithLog comp logs
|
||||
|
||||
putStrLn $ "\nResuming with logs:"
|
||||
logs2 <- waitLogged $ eachWithLog comp logs1
|
||||
logs2 <- waitLogged_ $ eachWithLog comp logs1
|
||||
|
||||
putStrLn $ "\nLogs at the end must be empty:"
|
||||
putStrLn $ show logs2
|
||||
|
||||
putStrLn $ "\nRunning the last log again using wait:"
|
||||
wait $ eachWithLog comp logs1
|
||||
wait_ $ eachWithLog comp logs1
|
||||
|
||||
where
|
||||
|
||||
comp = logged $ threads 5 $ do
|
||||
r <- logged $ each [1..3]
|
||||
logged $ liftIO $ print ("A",r)
|
||||
suspend
|
||||
logged $ liftIO $ print ("B",r)
|
||||
x <- logged $ (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
|
||||
suspend
|
||||
liftIO $ print ("C",r)
|
||||
liftIO $ print ("C", r, x)
|
||||
|
||||
event n = async (do putStrLn ("event" ++ show n); return n :: IO Int)
|
||||
|
Loading…
Reference in New Issue
Block a user