Idris2/tests/allschemes/channels004/Main.idr

19 lines
525 B
Idris
Raw Normal View History

2021-07-02 15:13:50 +03:00
import System.Concurrency
-- Simple producing thread.
producer : Channel Nat -> IO ()
producer c = ignore $ for [1..100] $ \n => channelPut c n
-- Test that using the same channel with multiple producers is okay.
main : IO ()
main =
do c <- makeChannel
tids <- for [1..10] $ \_ => fork (producer c)
vals <- for [1..1000] $ \_ => channelGet c
ignore $ traverse (\t => threadWait t) tids
let s = sum vals
if s == 50500
then putStrLn "Success!"
else putStrLn "How did we get here?"