Proposal: Improve the API for TChan, TMVar, and TVar
wren ng thornton
wren at freegeek.org
Sat Mar 26 10:29:29 CET 2011
I've found the following functions helpful for working with STM. Some of
them are just filling out the API so that TVars, TMVars, and IORefs
match better. And all the non-TVar functions can be optimized
considerably by including them in the STM library rather than defining
them externally. The implementations are obvious, so I'll just include
the types here; see the patch if you're interested.
-- | Non-blocking version of 'readTChan'.
tryReadTChan :: TChan a -> STM (Maybe a)
-- | Get the next value from the 'TChan' without removing it,
-- blocking if the channel is empty.
peekTChan :: TChan a -> STM a
-- | Non-blocking version of 'peekTChan'.
tryPeekTChan :: TChan a -> STM (Maybe a)
-- | Non-blocking version of 'readTMVar'.
tryReadTMVar :: TMVar a -> STM (Maybe a)
-- | Like 'modifyIORef' but for 'TVar'.
modifyTVar :: TVar a -> (a -> a) -> STM ()
-- | Strict version of 'modifyTVar'.
modifyTVar' :: TVar a -> (a -> a) -> STM ()
-- | Like 'swapTMVar' but for 'TVar'.
swapTVar :: TVar a -> a -> STM a
Discussion period: 2 weeks.
--
Live well,
~wren
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: stm-api-extras.dpatch
URL: <http://www.haskell.org/pipermail/libraries/attachments/20110326/52bfa713/attachment.asc>
More information about the Libraries
mailing list