Implements bounded channels. These channels differ from normal Chan
s in
that they are guaranteed to contain no more than a certain number of
elements. This is ideal when you may be writing to a channel faster than you
are able to read from it.
This module supports all the functions of Control.Concurrent.Chan except
unGetChan
and dupChan
, which are not supported for bounded channels.
- data BoundedChan a
- newBoundedChan :: Int -> IO (BoundedChan a)
- writeChan :: BoundedChan a -> a -> IO ()
- readChan :: BoundedChan a -> IO a
- isEmptyChan :: BoundedChan a -> IO Bool
- getChanContents :: BoundedChan a -> IO [a]
- writeList2Chan :: BoundedChan a -> [a] -> IO ()
Documentation
data BoundedChan a Source
BoundedChan
is an abstract data type representing a bounded channel.
newBoundedChan :: Int -> IO (BoundedChan a)Source
newBoundedChan n
returns a channel than can contain no more than n
elements.
writeChan :: BoundedChan a -> a -> IO ()Source
Write an element to the channel. If the channel is full, this routine will block until it is able to write. If you have multiple writers, be careful here, because the unlocking is not guaranteed to avoid starvation.
readChan :: BoundedChan a -> IO aSource
Read an element from the channel. If the channel is empty, this routine will block until it is able to read.
isEmptyChan :: BoundedChan a -> IO BoolSource
Returns True
if the supplied channel is empty.
getChanContents :: BoundedChan a -> IO [a]Source
Return a lazy list representing the contents of the supplied channel.
writeList2Chan :: BoundedChan a -> [a] -> IO ()Source
Write a list of elements to the channel. If the channel becomes full, this routine will block until it is able to write.