BoundedChan-1.0.0.0: Implementation of bounded Chans.

Control.Concurrent.BoundedChan

Description

Implements bounded channels. In these channels, you can give a rough maximum number of elements, and you will be guaranteed that no more than that number of elements will be pending within the channel.

This boundedness is ideal when you will be (or 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.

Synopsis

Documentation

data BoundedChan a Source

BoundedChan is an abstract data type representing an unbounded channel.

newBoundedChan :: Int -> IO (BoundedChan a)Source

Create a new bounded chan with size n.

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.

writeList2Chan :: BoundedChan a -> [a] -> IO ()Source

Write a list of elements to the channel. Note that this may block as it writes the list into the channel.