packages feed

stm-conduit (empty) → 0.2.0

raw patch · 4 files changed

+144/−0 lines, 4 filesdep +HUnitdep +QuickCheckdep +basesetup-changed

Dependencies added: HUnit, QuickCheck, base, conduit, stm, stm-chans, stm-conduit, test-framework, test-framework-hunit, test-framework-quickcheck2, transformers

Files

+ Data/Conduit/TMChan.hs view
@@ -0,0 +1,62 @@+-- | 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 Data.Conduit.TMChan ( module Control.Concurrent.STM.TMChan+                           , sourceTMChan+                           , sinkTMChan+                           ) where++import Control.Monad.IO.Class ( liftIO )+import Control.Concurrent.STM ( atomically )+import Control.Concurrent.STM.TMChan++import Data.Conduit++-- | 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.+sourceTMChan :: TMChan a -> Source IO a+sourceTMChan ch = src+    where+        src = Source pull close+        pull = do a <- liftIO . atomically $ readTMChan ch+                  case a of+                    Just x -> return $ Open src x+                    Nothing -> return $ Closed+        close = return () -- close is done by the sink.+{-# INLINE sourceTMChan #-}++-- | 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.+sinkTMChan :: TMChan a -> Sink a IO ()+sinkTMChan ch = sink+    where+        sink = SinkData push close+        push input = do liftIO . atomically $ writeTMChan ch input+                        return $ Processing push close+        close = liftIO . atomically $ closeTMChan ch+{-# INLINE sinkTMChan #-}
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Clark Gaebel++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Clark Gaebel nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ stm-conduit.cabal view
@@ -0,0 +1,50 @@+Name:                stm-conduit+Version:             0.2.0+Synopsis:            Introduces conduits to channels, and promotes using+                     conduits concurrently.+Description:         Provides two simple conduit wrappers around STM+                     channels - a source and a sink.+Homepage:            https://github.com/wowus/stm-conduit+License:             BSD3+License-file:        LICENSE+Author:              Clark Gaebel+Maintainer:          cgaebel@csclub.uwaterloo.ca+Category:            Concurrency, Conduit++Build-type:          Simple++Cabal-version:       >=1.8++Library+    Exposed-modules:   Data.Conduit.TMChan+    +    -- Packages needed in order to build this package.+    Build-depends:     base ==4.*,+                        transformers ==0.2.*,+                        stm == 2.2.*,+                        stm-chans ==1.2.*,+                        conduit ==0.2.*++    ghc-options:       -Wall -fwarn-tabs++test-suite stm-conduit-tests+    type:           exitcode-stdio-1.0+    main-is:        Test.hs+    hs-source-dirs: test/++    ghc-options:    -rtsopts=all++    Build-Depends:  base ==4.*,+                    QuickCheck >= 2,+                    HUnit,+                    test-framework,+                    test-framework-hunit,+                    test-framework-quickcheck2,+                    stm,+                    stm-conduit,+                    conduit,+                    stm-chans+  +source-repository head+    type:     git+    location: git://github.com/wowus/stm-conduit.git