Haskell by Example: Channel Buffering

original

You can treat TQueue as an unbounded FIFO channel.

import Control.Concurrent.STM

main = do
    messages <- atomically $ do
        msg <- newTQueue
        writeTQueue msg "buffered"
        writeTQueue msg "queue"
        return msg

    putStrLn =<< (atomically . readTQueue) messages
    putStrLn =<< (atomically . readTQueue) messages
$ runhaskell channel-buffering.hs
buffered
queue
back to index