HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Moduleconcurrency-1.11.0.3Haskell2010

Control.Concurrent.Classy.BoundedChan

Implements bounded channels. These channels differ from normal Chans 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.

Extra consistency: This version enforces that if thread Alice writes e1 followed by e2 then e1 will be returned by readBoundedChan before e2. Conversely, if thead Bob reads e1 followed by e2 then it was true that writeBoundedChan e1 preceded writeBoundedChan e2.

Previous versions did not enforce this consistency: if writeBoundedChan were preempted between putMVars or killThread arrived between putMVars then it can fail. Similarly it might fail if readBoundedChan were stopped after putMVar and before the second takeMVar. An unlucky pattern of several such deaths might actually break the invariants of the array in an unrecoverable way causing all future reads and writes to block.

  • 1 type
  • 7 values
valuewriteBoundedChan :: MonadConc m => BoundedChan m a -> a -> m ()
#

Write an element to the channel. If the channel is full, this routine will block until it is able to write. Blockers wait in a fair FIFO queue.

valuereadBoundedChan :: MonadConc m => BoundedChan m a -> m a
#

Read an element from the channel. If the channel is empty, this routine will block until it is able to read. Blockers wait in a fair FIFO queue.

valueisEmptyBoundedChan :: MonadConc m => BoundedChan m a -> m Bool
#

Deprecated. This isEmptyBoundedChan can block, no non-blocking substitute yet

Returns True if the supplied channel is empty.

NOTE: This may block on an empty channel if there is a blocked reader. NOTE: This function is deprecated.

valuewriteList2BoundedChan :: MonadConc m => BoundedChan m a -> [a] -> m ()
#

Write a list of elements to the channel. If the channel becomes full, this routine will block until it can write. Competing writers may interleave with this one.