unagi-chan-0.2.0.1: Fast and scalable concurrent queues for x86, with a Chan-like API

Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.Chan.Unagi.Unboxed

Contents

Synopsis

Creating channels

newChan :: Prim a => IO (InChan a, OutChan a) Source

Create a new channel, returning its write and read ends.

data InChan a Source

The write end of a channel created with newChan.

Instances

Eq (InChan a) 
Typeable (* -> *) InChan 

data OutChan a Source

The read end of a channel created with newChan.

Instances

Eq (OutChan a) 
Typeable (* -> *) OutChan 

Channel operations

Reading

readChan :: Prim a => OutChan a -> IO a Source

Read an element from the chan, blocking if the chan is empty.

Note re. exceptions: When an async exception is raised during a readChan the message that the read would have returned is likely to be lost, even when the read is known to be blocked on an empty queue. If you need to handle this scenario, you can use readChanOnException.

readChanOnException :: Prim a => OutChan a -> (IO a -> IO ()) -> IO a Source

Like readChan but allows recovery of the queue element which would have been read, in the case that an async exception is raised during the read. To be precise exceptions are raised, and the handler run, only when readChanOnException is blocking.

The second argument is a handler that takes a blocking IO action returning the element, and performs some recovery action. When the handler is called, the passed IO a is the only way to access the element.

getChanContents :: Prim a => OutChan a -> IO [a] Source

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

Writing

writeChan :: Prim a => InChan a -> a -> IO () Source

Write a value to the channel.

writeList2Chan :: Prim a => InChan a -> [a] -> IO () Source

Write an entire list of items to a chan type. Writes here from multiple threads may be interleaved, and infinite lists are supported.

Broadcasting

dupChan :: InChan a -> IO (OutChan a) Source

Duplicate a chan: the returned OutChan begins empty, but data written to the argument InChan from then on will be available from both the original OutChan and the one returned here, creating a kind of broadcast channel.