SampleVar

module Control.Concurrent.SampleVar
base Control.Concurrent.SampleVar
Sample variables
data SampleVar a
base Control.Concurrent.SampleVar
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.)
emptySampleVar :: SampleVar a -> IO ()
base Control.Concurrent.SampleVar
If the SampleVar is full, leave it empty. Otherwise, do nothing.
isEmptySampleVar :: SampleVar a -> IO Bool
base Control.Concurrent.SampleVar
Returns True if the SampleVar is currently empty. Note that this function is only useful if you know that no other threads can be modifying the state of the SampleVar, because otherwise the state of the SampleVar may have changed by the time you see the result of isEmptySampleVar.
newEmptySampleVar :: IO (SampleVar a)
base Control.Concurrent.SampleVar
Build a new, empty, SampleVar
newSampleVar :: a -> IO (SampleVar a)
base Control.Concurrent.SampleVar
Build a SampleVar with an initial value.
readSampleVar :: SampleVar a -> IO a
base Control.Concurrent.SampleVar
Wait for a value to become available, then take it and return.
writeSampleVar :: SampleVar a -> a -> IO ()
base Control.Concurrent.SampleVar
Write a value into the SampleVar, overwriting any previous value that was there.