stm-conduit-0.2.1: Introduces conduits to channels, and promotes using conduits concurrently.

Safe HaskellSafe-Infered

Data.Conduit.TMChan

Description

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.

Synopsis

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.

sinkTMChan :: TMChan a -> Sink a IO ()Source

A simple wrapper around a TMChan. As data is pushed into this sink, it will magically begin to appear in the channel. When the sink is closed, the channel will close too.