hspread-0.3.1: A client library for the spread toolkit

Portabilitynon-portable (concurrency)




Unbounded closeable channels.


The Chan type

data Chan t a Source

Chan is an abstract type representing an unbounded FIFO channel.

data R Source

R for ReadOnly

data W Source

W for WriteOnly


newChan :: IO (Chan R a, Chan W a)Source

Build and returns a pair of Chan, data written on the W end can be read from the R end.

writeChan :: Chan W a -> a -> IO BoolSource

Write a value to a Chan. Returns True if successful, False if the channel is closed.

closeChan :: Chan W a -> IO BoolSource

Close the Chan, data can be no more written to it. Returns True if the Chan was already closed.

isClosedChan :: Chan t a -> IO BoolSource

Non-blocking check.

readChan :: Chan R a -> IO (Maybe a)Source

Read the next value from the Chan. |Nothing if the Chan is closed.

forkChan :: Chan t a -> IO (Chan R a)Source

Forks a Chan: data that will be written (W) or is yet to be read (R) on the argument, will also be available on the returned channel.

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

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

isEmptyChan :: Chan R a -> IO BoolSource

Returns True if the supplied Chan is empty, i.e. readChan won't block.

Stream interface

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

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

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

Write an entire list of items to a Chan. Returning the remainder if the channel has been closed meanwhile.