Proposal: Improve the API for TChan, TMVar, and TVar

Edward Z. Yang ezyang at MIT.EDU
Sat Mar 26 10:42:26 CET 2011


+1

Excerpts from wren ng thornton's message of Sat Mar 26 05:29:29 -0400 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.
> 



More information about the Libraries mailing list