-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Write once concurrency primitives.
--
-- IVars are write-once (immutable) variables.
--
-- They can be read, an operation that will block until a value was
-- written to the variable. They can be written to exactly once.
@package ivar-simple
@version 0.2
-- | IVars are write-once variables.
--
-- Similarily to MVars, IVars can be either empty or
-- filled. Once filled, they keep their value indefinitely - they are
-- immutable.
--
-- Reading from an empty IVar will block until the IVar is
-- filled. Because the value read will never change, this is a pure
-- computation.
module Data.IVar.Simple
-- | A write-once (immutable) Variable
data IVar a
-- | Creates a new, empty IVar.
new :: IO (IVar a)
-- | Create a new filled IVar.
--
-- This is slightly cheaper than creating a new IVar and then
-- writing to it.
newFull :: a -> IO (IVar a)
-- | Returns the value of an IVar.
--
-- The evaluation will block until a value is written to the IVar
-- if there is no value yet.
read :: IVar a -> a
-- | Try to read an IVar. Returns Nothing if there is not
-- value yet.
tryRead :: IVar a -> IO (Maybe a)
-- | Writes a value to an IVar. Raises a NonTermination
-- exception if it fails.
write :: IVar a -> a -> IO ()
-- | Writes a value to an IVar. Returns True if successful.
tryWrite :: IVar a -> a -> IO Bool
-- | An IChans is a type of multicast channel built on top of
-- IVars. It supports multiple readers. The IChan data type
-- represents the head of a channel.
--
-- Writing to an IChan head has write-once semantics similar to
-- IVars: only the first of several attempts to write to the head
-- will succeed, returning a new IChan head for writing more
-- values.
module Data.IVar.Simple.IChan
-- | A channel head
data IChan a
-- | Create a new channel.
new :: IO (IChan a)
-- | Returns the contents of a channel as a list, starting at the channel
-- head.
--
-- This is a pure computation. Forcing elements of the list may, however,
-- block.
read :: IChan a -> [a]
-- | Write a single value to the channel.
--
-- Raises a NonTermination exception if a value has already been
-- written to the channel. Otherwise, returns a new channel head for
-- writing further values.
write :: IChan a -> a -> IO (IChan a)
-- | Attempts to write a single value to the channel.
--
-- If a value has already been written, returns Nothing.
-- Otherwise, returns a new channel head for writing further values.
tryWrite :: IChan a -> a -> IO (Maybe (IChan a))
-- | An MIChan is a multicast channel built on top of an
-- IChan.
--
-- Like IChan, this supports multiple readers. It is comparable to
-- a Control.Concurrent.Chan.Chan for the writing end: Each
-- write will append an element to the channel. No writes will fail.
module Data.IVar.Simple.MIChan
-- | A multicast channel.
data MIChan a
-- | Create a new multicast channel.
new :: IO (MIChan a)
-- | Return the list of values that the channel represents.
read :: MIChan a -> IO [a]
-- | Send a value across the channel.
write :: MIChan a -> a -> IO ()
-- | Send several values across the channel, atomically.
writeList :: MIChan a -> [a] -> IO ()