Safe Haskell | None |
---|---|
Language | Haskell2010 |
- newChan :: IO (InChan a, OutChan a)
- data InChan a
- data OutChan a
- readChan :: OutChan a -> IO a
- readChanOnException :: OutChan a -> (IO a -> IO ()) -> IO a
- getChanContents :: OutChan a -> IO [a]
- writeChan :: InChan a -> a -> IO ()
- writeList2Chan :: InChan a -> [a] -> IO ()
- dupChan :: InChan a -> IO (OutChan a)
Documentation
General-purpose concurrent FIFO queue. If you are trying to send messages of a primitive unboxed type, you may wish to use Control.Concurrent.Chan.Unagi.Unboxed which should be slightly faster and perform better when a queue grows very large. See also the bounded variant at Control.Concurrent.Chan.Unagi.Bounded.
Creating channels
The write end of a channel created with newChan
.
The read end of a channel created with newChan
.
Channel operations
Reading
readChan :: 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 :: 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 :: OutChan a -> IO [a] Source
Return a lazy list representing the contents of the supplied OutChan, much like System.IO.hGetContents.
Writing
writeList2Chan :: 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.