stm-split 0.0.1 → 0.0.2
raw patch · 3 files changed
+16/−21 lines, 3 files
Files
- src/Control/Concurrent/STM/Split/Class.hs +1/−1
- src/Control/Concurrent/STM/Split/MVar.hs +13/−18
- stm-split.cabal +2/−2
src/Control/Concurrent/STM/Split/Class.hs view
@@ -1,5 +1,5 @@ module Control.Concurrent.STM.Split.Class (- In, Out, C, newIO, new, read, write,+ In, Out, C(newIO, new, read, write), ) where import Control.Monad.STM (STM, )
src/Control/Concurrent/STM/Split/MVar.hs view
@@ -8,10 +8,7 @@ new, take, tryTake, put, tryPut,-{- write,- clear,--} ) where import qualified Control.Concurrent.STM.Split.Class as Split@@ -19,7 +16,7 @@ import qualified Control.Concurrent.STM.TMVar as MVar import Control.Monad.STM (STM, ) -import Prelude (IO, Maybe, Bool, return, )+import Prelude (IO, Maybe, Bool, fmap, ($), (.), return, (>>), ) newtype T dir a = Cons (MVar.TMVar a)@@ -34,25 +31,20 @@ read = take write = put +split :: MVar.TMVar a -> (In a, Out a)+split v = (Cons v, Cons v)+ newEmptyIO :: IO (In a, Out a)-newEmptyIO = do- v <- MVar.newEmptyTMVarIO- return (Cons v, Cons v)+newEmptyIO = fmap split $ MVar.newEmptyTMVarIO newEmpty :: STM (In a, Out a)-newEmpty = do- v <- MVar.newEmptyTMVar- return (Cons v, Cons v)+newEmpty = fmap split $ MVar.newEmptyTMVar newIO :: a -> IO (In a, Out a)-newIO a = do- v <- MVar.newTMVarIO a- return (Cons v, Cons v)+newIO = fmap split . MVar.newTMVarIO new :: a -> STM (In a, Out a)-new a = do- v <- MVar.newTMVar a- return (Cons v, Cons v)+new = fmap split . MVar.newTMVar take :: Out a -> STM a take (Cons v) = MVar.takeTMVar v@@ -67,7 +59,11 @@ tryPut (Cons v) a = MVar.tryPutTMVar v a -{-+{- |+Write value to 'MVar.TMVar' and overwrite existing content. It never blocks.+Please note, that this function is different+from the generic 'Class.write', which blocks on 'MVar.TMVar's.+-} write :: In a -> a -> STM () write var a = clear var >> put var a@@ -75,4 +71,3 @@ clear :: In a -> STM () clear (Cons v) = MVar.tryTakeTMVar v >> return ()--}
stm-split.cabal view
@@ -1,5 +1,5 @@ Name: stm-split-Version: 0.0.1+Version: 0.0.2 License: BSD3 License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -27,7 +27,7 @@ Cabal-Version: >=1.6 Build-Type: Simple Source-Repository this- Tag: 0.0.1+ Tag: 0.0.2 Type: darcs Location: http://hub.darcs.net/thielema/stm-split/