Add temporary test for CloseableChan
This commit is contained in:
parent
43cbb74abf
commit
1868cbfc00
1 changed files with 51 additions and 0 deletions
51
test/chantest.hs
Normal file
51
test/chantest.hs
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import Control.Concurrent
|
||||||
|
import qualified EuphApi.CloseableChan as E
|
||||||
|
|
||||||
|
thread1 c n = do
|
||||||
|
E.writeChan c n
|
||||||
|
thread1 c (n + 1)
|
||||||
|
|
||||||
|
thread2 c = do
|
||||||
|
val <- E.readChan c
|
||||||
|
case val of
|
||||||
|
Just j -> (print j) >> thread2 c
|
||||||
|
Nothing -> putStrLn "thread2 closed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
|
||||||
|
main1 = do
|
||||||
|
c <- E.newOpenChan
|
||||||
|
t1 <- forkIO $ thread1 c 0
|
||||||
|
t2 <- forkIO $ thread2 c
|
||||||
|
threadDelay $ 500*1000
|
||||||
|
E.closeChan c
|
||||||
|
threadDelay $ 500*1000
|
||||||
|
|
||||||
|
main2 = do
|
||||||
|
c <- E.newOpenChan
|
||||||
|
forkIO $ thread2 c
|
||||||
|
putStrLn "Go!"
|
||||||
|
|
||||||
|
mapM_ (E.writeChan c) [1..5]
|
||||||
|
-- putStrLn "added some numbers"
|
||||||
|
|
||||||
|
threadDelay $ 1000*1000
|
||||||
|
putStrLn "first second"
|
||||||
|
threadDelay $ 1000*1000
|
||||||
|
putStrLn "second second"
|
||||||
|
|
||||||
|
mapM_ (E.writeChan c) [6..10]
|
||||||
|
-- putStrLn "added more numbers"
|
||||||
|
|
||||||
|
threadDelay $ 1000*1000
|
||||||
|
putStrLn "third second"
|
||||||
|
threadDelay $ 1000*1000
|
||||||
|
putStrLn "fourth second"
|
||||||
|
|
||||||
|
E.closeChan c
|
||||||
|
-- putStrLn "channel closed"
|
||||||
|
|
||||||
|
threadDelay $ 1000*1000
|
||||||
|
putStrLn "fifth second"
|
||||||
|
threadDelay $ 1000*1000
|
||||||
|
putStrLn "sixth second"
|
||||||
|
|
||||||
|
main = main2
|
||||||
Loading…
Add table
Add a link
Reference in a new issue