TBChan is an abstract type representing a bounded FIFO
channel.
Modulestm-chans-3.0.0.9Haskell2010
Control.Concurrent.STM.TBChan
A version of Control.Concurrent.STM.TChan where the queue is
bounded in length. This variant incorporates ideas from Thomas
M. DuBuisson's bounded-tchan package in order to reduce
contention between readers and writers.
- 1 type
- 13 values
- Packagestm-chans-3.0.0.9
- Exports14
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceTBChan.hs
The TBChan type
1 declarationCreating TBChans
Build and returns a new instance of TBChan with the given
capacity. N.B., we do not verify the capacity is positive, but
if it is non-positive then writeTBChan will always retry and
isFullTBChan will always be true.
IO version of newTBChan. This is useful for creating
top-level TBChans using unsafePerformIO,
because using atomically inside
unsafePerformIO isn't possible.
Reading from TBChans
Read the next value from the TBChan, retrying if the channel
is empty.
A version of readTBChan which does not retry. Instead it
returns Nothing if no value is available.
Get the next value from the TBChan without removing it,
retrying if the channel is empty.
A version of peekTBChan which does not retry. Instead it
returns Nothing if no value is available.
Writing to TBChans
Write a value to a TBChan, retrying if the channel is full.
A version of writeTBChan which does not retry. Returns True
if the value was successfully written, and False otherwise.
Put a data item back onto a channel, where it will be the next item read. N.B., this could allow the channel to temporarily become longer than the specified limit, which is necessary to ensure that the item is indeed the next one read.
Predicates
Returns True if the supplied TBChan is empty (i.e., has
no elements). N.B., a TBChan can be both "empty" and
"full" at the same time, if the initial limit was non-positive.
Returns True if the supplied TBChan is full (i.e., is over
its limit). N.B., a TBChan can be both "empty" and "full"
at the same time, if the initial limit was non-positive. N.B.,
a TBChan may still be full after reading, if unGetTBChan was
used to go over the initial limit.
This is equivalent to: liftM (<= 0) estimateFreeSlotsTBMChan
Other functionality
Estimate the number of free slots. If the result is positive, then it's a minimum bound; if it's non-positive then it's exact. It will only be negative if the initial limit was negative or if unGetTBChan was used to go over the initial limit.
This function always contends with writers, but only contends with readers when it has to; compare against freeSlotsTBChan.
Return the exact number of free slots. The result can be negative if the initial limit was negative or if unGetTBChan was used to go over the initial limit.
This function always contends with both readers and writers; compare against estimateFreeSlotsTBChan.