ivar-simple-0.3.3: Write once concurrency primitives.

Copyright(c) 2008-2020 Bertram Felgenhauer
LicenseMIT
MaintainerBertram Felgenhauer <int-e@gmx.de>
Stabilityexperimental
Portabilityghc
Safe HaskellNone
LanguageHaskell2010

Data.IVar.Simple.IChan

Description

An IChans is a type of multicast channel built on top of IVars. It supports multiple readers. The channel is represented as a linked list. The IChan data type represents the head of a channel.

Writing to an IChan head has write-once semantics similar to IVars: only the first of several attempts to write to the head will succeed, returning a new IChan head for writing more values.

Synopsis

Documentation

data IChan a Source #

A channel head

Instances
Eq (IChan a) Source # 
Instance details

Defined in Data.IVar.Simple.IChan

Methods

(==) :: IChan a -> IChan a -> Bool #

(/=) :: IChan a -> IChan a -> Bool #

new :: IO (IChan a) Source #

Create a new channel.

read :: IChan a -> [a] Source #

Returns the contents of a channel as a list, starting at the channel head.

This is a pure computation. Forcing elements of the list may, however, block.

uncons :: IChan a -> (a, IChan a) Source #

Split channel into head and tail.

This is a pure operation, but it may block.

Since: 0.3.3

write :: IChan a -> a -> IO (IChan a) Source #

Write a single value to the channel.

Raises a BlockedIndefinitelyOnIVar exception if a value has already been written to the channel. Otherwise, returns a new channel head for writing further values.

tryWrite :: IChan a -> a -> IO (Maybe (IChan a)) Source #

Attempts to write a single value to the channel.

If a value has already been written, returns Nothing. Otherwise, returns a new channel head for writing further values.