caf-0.0.3: A library of Concurrency Abstractions using Futures.

Portabilitynon-portable (requires Futures)



This module implements a channel synchronisation primitive using buffers that block on futures. A channel is a linked list of buffers. It has a read-end at one side and a write-end at the other. Elements put into the channel can be read out in a first in, first out order. A read and a write operation can be executed in parallel by several threads. A channel has no capacity bounding.

The module contains similar functions as Control.Concurrent.Futures.Chan.

Warning: All operations on channels should only be used within the global wrapper function Futures.withFuturesDo!



data Chan a Source

A channel consists of a read-end buffer and a write-end buffer. The Itemtype is required to link the buffers in the channel.

type ChanType a = (Buffer (ItemType a), Buffer (ItemType a))Source

newChan :: IO (Chan a)Source

Creates a new empty channel.

writeChan :: Chan a -> a -> IO ()Source

Writes one value to a channel. A writeChan never blocks, since channels have no bounding limiters.

readChan :: Chan a -> IO aSource

Reads out an item from the read-head of the channel. It blocks on a empty channel.

writeChanContents :: Chan a -> [a] -> IO ()Source

Implements the same behaviour as writeChanContents from the module Control.Concurrent.Chan.

getChanContents :: Chan a -> IO [a]Source

Implements the same behaviour as getChanContents from the module Control.Concurrent.Chan. It reads permanently from the channel.

mergeChan :: [a] -> [a] -> Chan a -> IO (Chan a)Source

Writes two equally typed lists to a given channel in parallel.