Haskell Core Libraries (base package)ParentContentsIndex
Control.Concurrent.SampleVar
Portability non-portable (concurrency)
Stability experimental
Maintainer libraries@haskell.org
Description
Sample variables
Synopsis
type SampleVar a = MVar (Int, MVar a)
newEmptySampleVar :: IO (SampleVar a)
newSampleVar :: a -> IO (SampleVar a)
emptySampleVar :: SampleVar a -> IO ()
readSampleVar :: SampleVar a -> IO a
writeSampleVar :: SampleVar a -> a -> IO ()
Sample Variables
type SampleVar a = MVar (Int, MVar a)

Sample variables are slightly different from a normal MVar:

  • Reading an empty SampleVar causes the reader to block. (same as takeMVar on empty MVar)

  • Reading a filled SampleVar empties it and returns value. (same as takeMVar)

  • Writing to an empty SampleVar fills it with a value, and potentially, wakes up a blocked reader (same as for putMVar on empty MVar).

  • Writing to a filled SampleVar overwrites the current value. (different from putMVar on full MVar.)

newEmptySampleVar :: IO (SampleVar a)
Build a new, empty, SampleVar
newSampleVar :: a -> IO (SampleVar a)
Build a SampleVar with an initial value.
emptySampleVar :: SampleVar a -> IO ()
If the SampleVar is full, leave it empty. Otherwise, do nothing.
readSampleVar :: SampleVar a -> IO a
Wait for a value to become available, then take it and return.
writeSampleVar :: SampleVar a -> a -> IO ()
Write a value into the SampleVar, overwriting any previous value that was there.
Produced by Haddock version 0.3