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


-- | A concurrency primitive for a slow consumer.
--   
--   A concurrency primitive for a slow consumer that can tolerate missing
--   some updates.
@package next-ref
@version 0.1.0.2


-- | This package contains a concurrency primitive which can be used to
--   limit an expensive consumer from running unnecessarily. Crucially the
--   consumer must be able to tolerate missing some updates.
--   
--   <a>NextRef</a> provides non-blocking writes, blocking reads, and
--   non-blocking reads.
--   
--   The blocking read interface (<a>takeNextRef</a>) will not necessarily
--   present all values.
--   
--   Additionally the <a>NextRef</a> can be <tt>closed</tt>. This is useful
--   to graceful shutdown the consumer when the producer closes the
--   <a>NextRef</a>
module Control.Concurrent.NextRef

-- | A concurrency primitive for a slow consumer that can tolerate missing
--   some updates.
data NextRef a

-- | Create a <tt>NextVar</tt>
newNextRef :: a -> IO (NextRef a)

-- | Block until the next value is available. If the <tt>NextVar</tt> is
--   closed it returns <a>Nothing</a> immediantly.
takeNextRef :: NextRef a -> IO (Maybe a)

-- | Read the most recent value. Non-blocking
readLast :: NextRef a -> IO a

-- | Write a new value. Never blocks.
writeNextRef :: NextRef a -> a -> IO ()

-- | Apply a function to current value to produce the next value and return
--   a result.
modifyNextRef :: NextRef a -> (a -> (a, b)) -> IO b

-- | Modify the status of the <a>NextRef</a> to <a>Closed</a>. All future
--   reads using <a>takeNextRef</a> will result a <a>Nothing</a>.
--   <a>readLast</a> is unaffected.
close :: NextRef a -> IO ()

-- | Modify the status of the <a>NextRef</a> to <a>Closed</a>. All future
--   reads using <a>takeNextRef</a> will return a <a>Just</a>.
--   <a>readLast</a> is unaffected.
open :: NextRef a -> IO ()

-- | Get the current status of the <a>NextRef</a>
status :: NextRef a -> IO Status

-- | Status is used to prevent future reads. When the status is
--   <a>Closed</a> <a>takeNextRef</a> will always return <a>Nothing</a>.
--   When the status is open it will return Just. This is based off of the
--   design of <tt>TMQueue</tt> from the 'stm-chans' package.
data Status
Open :: Status
Closed :: Status
instance GHC.Enum.Bounded Control.Concurrent.NextRef.Status
instance GHC.Enum.Enum Control.Concurrent.NextRef.Status
instance GHC.Read.Read Control.Concurrent.NextRef.Status
instance GHC.Classes.Ord Control.Concurrent.NextRef.Status
instance GHC.Classes.Eq Control.Concurrent.NextRef.Status
instance GHC.Show.Show Control.Concurrent.NextRef.Status
