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


-- | Skip variables
--   
--   Please see the README on GitHub at
--   <a>https://github.com/leohaskell/skip-var#readme</a>
@package skip-var
@version 0.1.1.0


-- | Implementation of skip variables - a special case of <a>skip
--   channels</a>, the difference being that a value stored in a skip
--   variable can be read at most once, while a skip channel can have
--   multiple readers (i.e. <i>multiple readers</i> can read the same
--   value).
--   
--   Writing into a skip variable doesn't block - if there's a value
--   stored, it's overwritten. Reading, on the other hand, blocks, if there
--   isn't a new value since the last read, or if the skip variable is
--   empty.
--   
--   <h3>Some examples:</h3>
--   
--   <pre>
--   s &lt;- newEmptySVar :: IO (SVar Int)
--   print =&lt;&lt; readSVar s -- blocks
--   </pre>
--   
--   <pre>
--   s &lt;- newSVar 42 :: IO (SVar Int)
--   print =&lt;&lt; readSVar s -- prints 42
--   print =&lt;&lt; readSVar s -- blocks
--   </pre>
--   
--   The next few lines will print some of the numbers between 0 and 10000.
--   Note that at least one number will be printed, but many will be
--   skipped, because <a>print</a>ing is slow.
--   
--   <pre>
--   import Control.Concurrent (forkIO, killThread)
--   import Control.Monad (forever)
--   
--   s &lt;- newEmptySVar :: IO (SVar Int)
--   tid &lt;- forkIO $ forever $ print =&lt;&lt; readSVar s
--   mapM_ (putSVar s) [0..10000]
--   killThread tid
--   </pre>
module Control.Concurrent.SVar

-- | An <a>SVar</a> (skip variable) is a variable which allows for
--   non-blocking updates, and blocking reads if the stored data has been
--   read already, or if there is no data.
data SVar a

-- | Create an empty <a>SVar</a>.
newEmptySVar :: IO (SVar a)

-- | Create an <a>SVar</a> which contains the supplied value.
newSVar :: a -> IO (SVar a)

-- | Put a value into an <a>SVar</a>. Never blocks, always overwrites the
--   current value, if there is one.
putSVar :: SVar a -> a -> IO ()

-- | Read a value from an <a>SVar</a>. Blocks if there isn't a new value
--   since the last read, or if the <a>SVar</a> is empty.
readSVar :: SVar a -> IO a
