HORIZON HASKELLDocslts/ghc-9.14.x7a6c33e2026-10-12Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 7a6c33e · 2026-10-12

The TBMQueue type

datadata TBMQueue a

TBMQueue is an abstract type representing a bounded closeable FIFO queue.

Creating TBMQueues

Reading from TBMQueues

valuereadTBMQueue :: TBMQueue a -> STM (Maybe a)

Read the next value from the TBMQueue, retrying if the queue is empty (and not closed). We return Nothing immediately if the queue is closed and empty.

Writing to TBMQueues

valuewriteTBMQueue :: TBMQueue a -> a -> STM ()

Write a value to a TBMQueue, retrying if the queue is full. If the queue is closed then the value is silently discarded. Use isClosedTBMQueue to determine if the queue is closed before writing, as needed.

valuetryWriteTBMQueue :: TBMQueue a -> a -> STM (Maybe Bool)

A version of writeTBMQueue which does not retry. Returns Just True if the value was successfully written, Just False if it could not be written (but the queue was open), and Nothing if it was discarded (i.e., the queue was closed).

valueunGetTBMQueue :: TBMQueue a -> a -> STM ()

Put a data item back onto a queue, where it will be the next item read. If the queue is closed then the value is silently discarded; you can use peekTBMQueue to circumvent this in certain circumstances. N.B., this could allow the queue to temporarily become longer than the specified limit, which is necessary to ensure that the item is indeed the next one read.

Closing TBMQueues

Predicates

Returns True if the supplied TBMQueue is empty (i.e., has no elements). N.B., a TBMQueue can be both "empty" and "full" at the same time, if the initial limit was non-positive.

Returns True if the supplied TBMQueue is full (i.e., is over its limit). N.B., a TBMQueue can be both "empty" and "full" at the same time, if the initial limit was non-positive. N.B., a TBMQueue may still be full after reading, if unGetTBMQueue was used to go over the initial limit.

This is equivalent to: liftM (<= 0) estimateFreeSlotsTBMQueue

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 unGetTBMQueue 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 freeSlotsTBMQueue.