
On 26 March 2011 21:30, wren ng thornton
On 3/26/11 11:43 AM, Antoine Latter wrote:
On Sat, Mar 26, 2011 at 6:26 AM, Bas van Dijk
wrote: On 26 March 2011 10:29, wren ng thornton
wrote: tryReadTChan :: TChan a -> STM (Maybe a)
+1 if we also add: tryReadChan :: Chan a -> IO (Maybe a)
peekTChan :: TChan a -> STM a tryPeekTChan :: TChan a -> STM (Maybe a)
+1 if we also add: peekChan :: Chan a -> IO a tryPeekChan :: Chan a -> IO (Maybe a)
Here's the last time 'tryReadChan' came up, for reference: http://thread.gmane.org/gmane.comp.lang.haskell.libraries/14596
I feel like these sorts of operations are much easier to get right in STM.
Agreed. I'm all for adding Chan versions to base if we can get the implementation/semantics right, but since I don't have experience with Chans I'm not sure if I'm the best person for that task.
The attached patch adds: tryReadMVar :: MVar a -> IO (Maybe a) tryReadChan :: Chan a -> IO (Maybe a) peekChan :: Chan a -> IO a tryPeekChan :: Chan a -> IO (Maybe a) tryReadMVar and tryReadChan were taken from the patch from Mitar. Thanks Antoine for linking that ticket. Someone should definitely take a closer look at peekChan and tryPeekChan and verify if they're correct. Wren, something else: in the documentation of your new STM operations you talk about "blocking". I think it's clearer and more consistent with the rest of STM if you talk about "retrying" instead. Regards, Bas