base-4.6.0.1: Basic libraries

Portability | non-portable (concurrency)
Stability | experimental
Maintainer | libraries@haskell.org
Safe Haskell | Trustworthy

Control.Concurrent.Chan

Contents

- The `Chan` type
- Operations
- Stream interface

Description

Unbounded channels.

Synopsis

- data Chan a
- newChan :: IO (Chan a)
- writeChan :: Chan a -> a -> IO ()
- readChan :: Chan a -> IO a
- dupChan :: Chan a -> IO (Chan a)
- unGetChan :: Chan a -> a -> IO ()
- isEmptyChan :: Chan a -> IO Bool
- getChanContents :: Chan a -> IO [a]
- writeList2Chan :: Chan a -> [a] -> IO ()

# The `Chan` type

data Chan a

`Chan` is an abstract type representing an unbounded FIFO channel.

Instances

Typeable1 Chan |
Eq (Chan a) |

# Operations

newChan :: IO (Chan a)

Build and returns a new instance of `Chan`.

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

Write a value to a `Chan`.

readChan :: Chan a -> IO a

Read the next value from the `Chan`.

dupChan :: Chan a -> IO (Chan a)

Duplicate a `Chan`: the duplicate channel begins empty, but data written to either channel from then on will be available from both. Hence this creates a kind of broadcast channel, where data written by anyone is seen by everyone else.

(Note that a duplicated channel is not equal to its original. So: `fmap (c /=) $ dupChan c` returns `True` for all `c`.)

unGetChan :: Chan a -> a -> IO ()

Deprecated: if you need this operation, use Control.Concurrent.STM.TChan instead. See http:hackage.haskell.orgtracghcticket4154 for details

Put a data item back onto a channel, where it will be the next item read.

isEmptyChan :: Chan a -> IO Bool

Deprecated: if you need this operation, use Control.Concurrent.STM.TChan instead. See http:hackage.haskell.orgtracghcticket4154 for details

Returns `True` if the supplied `Chan` is empty.

# Stream interface

getChanContents :: Chan a -> IO [a]

Return a lazy list representing the contents of the supplied `Chan`, much like `hGetContents`.

writeList2Chan :: Chan a -> [a] -> IO ()

Write an entire list of items to a `Chan`.