Idris2/tests/chez/channels003/Main.idr
2021-07-02 13:13:50 +01:00

20 lines
497 B
Idris

import System.Concurrency
-- Simple looping thread
consumer : Channel Nat -> IO ()
consumer c =
do (S k) <- channelGet c
| Z => pure ()
consumer c
-- Test that using the same channel with multiple consumers is okay.
main : IO ()
main =
do c <- makeChannel
tids <- for [1..7] $ \_ => fork (consumer c)
ignore $ for [1..100] $ \_ => channelPut c 1
ignore $ for [1..7] $ \_ => channelPut c Z
ignore $ traverse (\t => threadWait t) tids
putStrLn "Success!"