Idris2/tests/allschemes/channels003/Main.idr

20 lines
497 B
Idris
Raw Normal View History

2021-07-02 15:13:50 +03:00
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!"