Safe Haskell | None |
---|---|
Language | Haskell98 |
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.
Documentation
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
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
is==
bFalse
, then after
will not causeforwardChan
a ba
to become==
bTrue
.