-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Broadcast channel type that avoids 0 reader space leaks.
--   
--   A variation of <a>Control.Concurrent.Chan</a> from base, which allows
--   to the easy creation of broadcast channels without the space-leaks
--   that may arise from using <a>Control.Concurrent.Chan.dupChan</a>. The
--   <a>Control.Concurrent.Chan.Chan</a> type from
--   <a>Control.Concurrent.Chan</a> consists of both a read and write end.
--   This presents a problem when one wants to have a broadcast channel
--   that, at times, has zero listeners. To write to a
--   <a>Control.Concurrent.Chan.Chan</a> there must always be a read end
--   and this read end will hold ALL messages alive until read. The simple
--   solution applied in this module is to separate read and write ends. As
--   a result, any messages written to the write end can be immediately
--   garbage collected if there are no active read ends, avoding space
--   leaks.
@package broadcast-chan
@version 0.1.1


-- | A variation of <a>Control.Concurrent.Chan</a> from base, which allows
--   to the easy creation of broadcast channels without the space-leaks
--   that may arise from using <a>dupChan</a>.
--   
--   The <a>Chan</a> type from <a>Control.Concurrent.Chan</a> consists of
--   both a read and write end. This presents a problem when one wants to
--   have a broadcast channel that, at times, has zero listeners. To write
--   to a <a>Chan</a> there must always be a read end and this read end
--   will hold ALL messages alive until read.
--   
--   The simple solution applied in this module is to separate read and
--   write ends. As a result, any messages written to the write end can be
--   immediately garbage collected if there are no active read ends,
--   avoding space leaks.
module Control.Concurrent.BroadcastChan

-- | The abstract type representing the read or write end of a
--   <a>BroadcastChan</a>.
data BroadcastChan (d :: Direction) a

-- | Alias for the <a>In</a> type from the <a>Direction</a> kind, allows
--   users to write the 'BroadcastChan In a' type without enabling
--   DataKinds.
type In =  'In

-- | Alias for the <a>Out</a> type from the <a>Direction</a> kind, allows
--   users to write the 'BroadcastChan Out a' type without enabling
--   DataKinds.
type Out =  'Out

-- | Creates a new <a>BroadcastChan</a> write end.
newBroadcastChan :: IO (BroadcastChan In a)

-- | Write a value to write end of a <a>BroadcastChan</a>. Any messages
--   written while there are no live read ends can be immediately garbage
--   collected, thus avoiding space leaks.
writeBChan :: BroadcastChan In a -> a -> IO ()

-- | Read the next value from the read end of a <a>BroadcastChan</a>.
readBChan :: BroadcastChan Out a -> IO a

-- | Create a new read end for a <a>BroadcastChan</a>. Will receive all
--   messages written to the channel's write end after the read end's
--   creation.
newBChanListener :: BroadcastChan In a -> IO (BroadcastChan Out a)
instance GHC.Classes.Eq (Control.Concurrent.BroadcastChan.BroadcastChan d a)
