module Main
( main
) where
import Control.Concurrent (forkIO, threadDelay)
import Control.Concurrent.STM (atomically, newTQueueIO, newTVarIO, readTQueue, readTVar, writeTVar)
main :: IO ()
main = do
continue <- newTVarIO True
queue <- newTQueueIO
forkIO $ do
putStrLn "Start"
atomically $ do
continue' <- readTVar continue
if continue'
then readTQueue queue
else pure ()
putStrLn "Finish"
threadDelay 1000000
atomically $
writeTVar continue False
pure ()