Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: wren ng thornton <wren <at> freegeek.org>
Subject: Proposal: Improve the API for TChan, TMVar, and TVar
Newsgroups: gmane.comp.lang.haskell.libraries
Date: Saturday 26th March 2011 09:29:29 UTC (over 6 years ago)
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
 
CD: 3ms