Proposal: Add tryReadChan to Chan

Mitar mmitar at gmail.com
Wed Dec 1 01:25:32 CET 2010


Hi!

On Wed, Dec 1, 2010 at 12:55 AM, Antoine Latter <aslatter at gmail.com> wrote:
> All of this really feels like what STM is good at. It might help if you
> explained why TChans are not well suited to your task.

Because it has too much overhead (I haven't tested it for my
particular application but it is based on comment for isEmptyChan). I
understand that Chans are more lightweight and once isEmptyChan was
deprecated I discovered that for my purposes (non-blocking read) I do
not need isEmptyChan and that code can be written without problems
isEmptyChan has (mostly because there is a subtle change in
semantics).

So sometimes you have a work to do and you just want to check if there
is something new in Chan and if it is not continue with your work.

If you are interested where I am using it you can check my library Etage:

http://hackage.haskell.org/package/Etage

where I have such function:

slurpChan :: Chan a -> IO [a]
slurpChan chan = slurpChan' []
  where slurpChan' cs = do
          mc <- tryReadChan chan
          case mc of
            Nothing -> return cs
            Just c  -> slurpChan' (c:cs)


Mitar



More information about the Libraries mailing list