PROPOSAL: Add newBroadcastChan :: IO (Chan a) to Control.Concurrent.Chan

Merijn Verstraaten merijn at inconsistent.nl
Tue Sep 9 07:30:40 UTC 2014


Ola!

Control.Concurrent.STM.TChan has the “newBroadcastTChan :: STM (TChan a)”, this creates a “write-only” TChan to avoid any space leaks when a Chan is written too but never read from (for example, when dupTChan is used to hand a copy to threads). Unfortunately, no such variant seems to exist for the normal Chan? I have the following code:

foo :: Chan a -> IO Foo
foo broadcast = do
    newListener <- dupChan broadcast
    forkIO $ doStuffWith newListener

This means the original Chan is never read from and much like the problem with TChan, values keep piling up in the original channel, causing a space leak. I propose adding

newBroadcastChan :: IO (Chan a)

The obvious Chan equivalent of newBroadcastTChan, which creates a write-only channel without read end, thus avoiding this space leak.

Discussion: 2 weeks?

Cheers,
Merijn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140909/ca55450b/attachment.sig>


More information about the Libraries mailing list