bounded-tchan-0.2.3: Bounded Transactional channels (queues)




data BTChan a Source

A BTChan is a bounded TChan - a FIFO channel using TChan and a transactional variable to limit the number of elements on the channel.

newBTChan :: Int -> STM (BTChan a)Source

newBTChan m make a new bounded TChan of max size m.

newBTChanIO :: Int -> IO (BTChan a)Source

An IO version of newBTChanIO. This should be useful with unsafePerformIO in the same manner as newTVarIO and newTChanIO are used.

writeBTChan :: BTChan a -> a -> STM ()Source

Writes the value to the BTChan or blocks if the channel is full.

readBTChan :: BTChan a -> STM aSource

Reads the next value from the BTChan

tryWriteBTChan :: BTChan a -> a -> STM BoolSource

A non-blocking write that returns True if the write succeeded, False otherwise.

tryReadBTChan :: BTChan a -> STM (Maybe a)Source

A non-blocking read that returns 'Just a' on success and Nothing when the channel is empty.

isEmptyBTChan :: BTChan a -> STM BoolSource

Returns True if the supplied TChan is empty.

sizeOfBTChan :: BTChan a -> STM IntSource

Get the current number of elements in the BTChan.

setMaxOfBTChan :: BTChan a -> Int -> BTChan aSource

let c2 = setMaxOfBTChan c1 mx Using the same underlying TChan, set a new maximum number of messages, mx. If the current size is greater than mx then no messages are dropped, but writes will block till the size goes lower than mx. Using c2 and c1 concurrently is possible, but c2 writes will block at the new maximum while writes to c1 will block at the new, making it biased against whichever writer has the channel with the smaller bound.

maxOfBTChan :: BTChan a -> IntSource

Get the bound of the BTChan.