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

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


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?

-------------- 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: <>

More information about the Libraries mailing list