Ticket #7986: broadcastTChan.patch

File broadcastTChan.patch, 1.2 KB (added by klao, 2 years ago)

patch for the proposed change

  • Control/Concurrent/STM/TChan.hs

    diff --git a/Control/Concurrent/STM/TChan.hs b/Control/Concurrent/STM/TChan.hs
    index a587079..0a134d2 100644
    a b newTChanIO = do 
    7878  write <- newTVarIO hole
    7979  return (TChan read write)
    8080
    81 -- | Create a write-only 'TChan'.  More precisely, 'readTChan' will 'retry'
    82 -- even after items have been written to the channel.  The only way to read
    83 -- a broadcast channel is to duplicate it with 'dupTChan'.
     81-- | Create a write-only 'TChan'.  The only way to read a broadcast
     82-- channel is to duplicate it with 'dupTChan'.  Doing a 'readTChan' on
     83-- the broadcast channel itself will throw an 'error'.
    8484--
    8585-- Consider a server that broadcasts messages to clients:
    8686--
    newBroadcastTChan = do 
    105105-- | @IO@ version of 'newBroadcastTChan'.
    106106newBroadcastTChanIO :: IO (TChan a)
    107107newBroadcastTChanIO = do
    108     dummy_hole <- newTVarIO TNil
    109108    write_hole <- newTVarIO TNil
    110     read <- newTVarIO dummy_hole
     109    read <- newTVarIO (error "reading from a TChan created by newBroadcastTChanIO; use dupTChan first")
    111110    write <- newTVarIO write_hole
    112111    return (TChan read write)
    113112