Safe Haskell | Safe-Infered |
---|
Contains a simple source and sink for linking together conduits in in different threads. Usage is so easy, it's best explained with an example:
We first create a channel for communication...
do chan <- atomically $ newTMChan
Then we fork a new thread loading a wackton of pictures into memory. The data (pictures, in this case) will be streamed down the channel to whatever is on the other side.
_ <- forkIO . runResourceT $ loadTextures lotsOfPictures $$ sinkTMChan chan
Finally, we connect something to the other end of the channel. In this case, we connect a sink which uploads the textures one by one to the graphics card.
runResourceT $ sourceTMChan chan $$ Conduit.mapM_ (liftIO . uploadToGraphicsCard)
By running the two tasks in parallel, we no longer have to wait for one texture to upload to the graphics card before reading the next one from disk. This avoids the common switching of bottlenecks (such as between the disk and graphics memory) that most loading processes seem to love.
Control.Concurrent.STM.TMChan is re-exported for convenience.
- module Control.Concurrent.STM.TMChan
- sourceTMChan :: TMChan a -> Source IO a
- sinkTMChan :: TMChan a -> Sink a IO ()
Documentation
sourceTMChan :: TMChan a -> Source IO aSource
A simple wrapper around a TMChan. As data is pushed into the channel, the source will read it and pass it down the conduit pipeline. When the channel is closed, the source will close also.