module Game.LambdaHack.Common.Thread
( forkChild, waitForChildren
) where
import Prelude ()
import Game.LambdaHack.Common.Prelude
import Control.Concurrent.Async
import Control.Concurrent.MVar
forkChild :: MVar [Async ()] -> IO () -> IO ()
forkChild children io = do
a <- async io
link a
childs <- takeMVar children
putMVar children (a : childs)
waitForChildren :: MVar [Async ()] -> IO ()
waitForChildren children = do
cs <- takeMVar children
case cs of
[] -> return ()
m : ms -> do
putMVar children ms
wait m
waitForChildren children