stm-chans 1.0.0 → 1.1.0
raw patch · 3 files changed
+39/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Concurrent.STM.TBChan: tryWriteTBChan :: TBChan a -> a -> STM Bool
+ Control.Concurrent.STM.TBMChan: tryWriteTBMChan :: TBMChan a -> a -> STM (Maybe Bool)
Files
- src/Control/Concurrent/STM/TBChan.hs +15/−1
- src/Control/Concurrent/STM/TBMChan.hs +21/−1
- stm-chans.cabal +3/−3
src/Control/Concurrent/STM/TBChan.hs view
@@ -1,7 +1,7 @@ {-# OPTIONS_GHC -Wall -fwarn-tabs #-} {-# LANGUAGE CPP, DeriveDataTypeable #-} ------------------------------------------------------------------- 2011.04.03+-- 2011.04.05 -- | -- Module : Control.Concurrent.STM.TBChan -- Copyright : Copyright (c) 2011 wren ng thornton@@ -28,6 +28,7 @@ , tryPeekTBChan -- ** Writing to TBChans , writeTBChan+ , tryWriteTBChan , unGetTBChan -- ** Predicates , isEmptyTBChan@@ -117,6 +118,19 @@ else do writeTChan chan x modifyTVar' limit (subtract 1)+++-- | A version of 'writeTBChan' which does not retry. Returns @True@+-- if the value was successfully written, and @False@ otherwise.+tryWriteTBChan :: TBChan a -> a -> STM Bool+tryWriteTBChan self@(TBChan limit chan) x = do+ b <- isFullTBChan self+ if b+ then return False+ else do+ writeTChan chan x+ modifyTVar' limit (subtract 1)+ return True -- | Put a data item back onto a channel, where it will be the next
src/Control/Concurrent/STM/TBMChan.hs view
@@ -1,7 +1,7 @@ {-# OPTIONS_GHC -Wall -fwarn-tabs #-} {-# LANGUAGE CPP, DeriveDataTypeable #-} ------------------------------------------------------------------- 2011.04.03+-- 2011.04.05 -- | -- Module : Control.Concurrent.STM.TBMChan -- Copyright : Copyright (c) 2011 wren ng thornton@@ -29,6 +29,7 @@ , tryPeekTBMChan -- ** Writing to TBMChans , writeTBMChan+ , tryWriteTBMChan , unGetTBMChan -- ** Closing TBMChans , closeTBMChan@@ -154,6 +155,25 @@ else do writeTChan chan x modifyTVar' limit (subtract 1)+++-- | A version of 'writeTBMChan' which does not retry. Returns @Just+-- True@ if the value was successfully written, @Just False@ if it+-- could not be written (but the channel was open), and @Nothing@+-- if it was discarded (i.e., the channel was closed).+tryWriteTBMChan :: TBMChan a -> a -> STM (Maybe Bool)+tryWriteTBMChan self@(TBMChan closed limit chan) x = do+ b <- readTVar closed+ if b+ then return Nothing+ else do+ b' <- isFullTBMChan self+ if b'+ then return (Just False)+ else do+ writeTChan chan x+ modifyTVar' limit (subtract 1)+ return (Just True) -- | Put a data item back onto a channel, where it will be the next
stm-chans.cabal view
@@ -1,9 +1,9 @@ ------------------------------------------------------------------- wren ng thornton <wren@community.haskell.org> ~ 2011.04.03+-- wren ng thornton <wren@community.haskell.org> ~ 2011.04.05 ---------------------------------------------------------------- Name: stm-chans-Version: 1.0.0+Version: 1.1.0 -- Source-Repository requires version 1.6 Cabal-Version: >= 1.6 -- We need a custom build in order to define __HADDOCK__@@ -15,7 +15,7 @@ Author: wren ng thornton Maintainer: wren@community.haskell.org Homepage: http://code.haskell.org/~wren/-Category: System+Category: Concurrency Synopsis: Additional types of channels for STM. Description: Additional types of channels for STM.