forward-chan-0.0.0.0: Concurrent channels with a forwarding primitive

Control.Concurrent.Chan.Forwardable

Description

A concurrent FIFO queue which behaves like Base's Chan with the new added forward primative for merging two channels. Unlike duplicate style merging, when two channels are forwarded to each other, writes to one channel will not be duplicated to both channels, rather it will be as if both channels contents had been merged and all their outstanding and future references now point to this new channel.

See http://github.com/mmirman/forward-chan for futher specification.

Synopsis

# Documentation

data Chan a Source #

A forwardable channel. It supports all the standard channel operations as layed out in the base library (as of 4.10.0.0) except dupChan

Instances

 Eq (Chan a) Source # Methods(==) :: Chan a -> Chan a -> Bool #(/=) :: Chan a -> Chan a -> Bool #

newChan :: IO (Chan a) Source #

Create a new channel

writeChan :: Chan t -> t -> IO () Source #

Write a value to the channel.

If the channel becomes forwarded at any time in the future, any thread waiting on a value from the forwarded channel may receive this value.

readChan :: Chan a -> IO a Source #

Read a value from a channel.

If a thread is waiting at a readChan and another thread forwards this channel to another (or visa versa) and the other channel contains elements, this read might now consume that element.

forwardChan :: Chan a -> Chan a -> IO () Source #

Forward takes two channels and makes them act as one. It obeys a few properties:

• Commutivity: forwardChan a b === forwardChan b a
• Behavioral Transitivity: (forwardChan a b >> forwardChan b c) === (forwardChan a b >> forwardChan a c)
• Equal Opportunity: A write to either channel before or after the forward will be able to be consumed by a read on either of the channels, and there will be no unexpected starvation or race conditions.
• Early Bird Gets The Worm: The first thread to read from either channel will, after a forward, always recieve the next available item. Similarly, items written to either channel are read in the same order they were written in.
• Note: if a == b is False, then after forwardChan a b will not cause a == b to become True.

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

Return a lazy list representing the contents of the supplied Chan

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

Write an entire list of items to a Chan.