stm-conduit-4.0.0: Introduces conduits to channels, and promotes using conduits concurrently.

Safe HaskellNone
LanguageHaskell98

Data.Conduit.TQueue

Contents

Description

Contains a simple source and sink linking together conduits in different threads. For extended examples of usage and bottlenecks see TMChan.

TQueue is an amoritized FIFO queue behaves like TChan, with two important differences:

  • it's faster (but amortized thus the cost of individual operations may vary a lot)
  • it doesn't provide equivalent of the dupTChan and cloneTChan operations

Here is short description of data structures:

  • TQueue - unbounded infinite queue
  • TBQueue - bounded infinite queue
  • TMQueue - unbounded finite (closable) queue
  • TBMQueue - bounded finite (closable) queue

Caveats

Infinite operations means that source doesn't know when stream is ended so one need to use other methods of finishing stream like sending an exception or finish conduit in downstream.

Synopsis

Connectors

Infinite queues

sourceTQueue :: MonadIO m => TQueue a -> ConduitT z a m () Source #

A simple wrapper around a TQueue. As data is pushed into the queue, the source will read it and pass it down the conduit pipeline.

sinkTQueue :: MonadIO m => TQueue a -> ConduitT a z m () Source #

A simple wrapper around a TQueue. As data is pushed into this sink, it will magically begin to appear in the queue.

TBQueue connectors

sourceTBQueue :: MonadIO m => TBQueue a -> ConduitT z a m () Source #

A simple wrapper around a TBQueue. As data is pushed into the queue, the source will read it and pass it down the conduit pipeline.

sinkTBQueue :: MonadIO m => TBQueue a -> ConduitT a z m () Source #

A simple wrapper around a TBQueue. As data is pushed into this sink, it will magically begin to appear in the queue.

entangledPair :: MonadIO m => Int -> m (ConduitT z a m (), ConduitT a l m ()) Source #

A convenience wrapper for creating a source and sink TBQueue of the given size at once, without exposing the underlying queue.

Returns release key that can be used for premature close of the communication channel, otherwise channel will be closed when the ResourceT scope will be closed.

Closable queues

TMQueue connectors

sourceTMQueue :: MonadIO m => TMQueue a -> ConduitT z a m () Source #

A simple wrapper around a TMQueue. As data is pushed into the queue, the source will read it and pass it down the conduit pipeline. When the queue is closed, the source will close also.

sinkTMQueue :: MonadIO m => TMQueue a -> ConduitT a z m () Source #

A simple wrapper around a TMQueue. As data is pushed into this sink, it will magically begin to appear in the queue.

TBMQueue connectors

sourceTBMQueue :: MonadIO m => TBMQueue a -> ConduitT z a m () Source #

A simple wrapper around a TBMQueue. As data is pushed into the queue, the source will read it and pass it down the conduit pipeline. When the queue is closed, the source will close also.

sinkTBMQueue :: MonadIO m => TBMQueue a -> ConduitT a z m () Source #

A simple wrapper around a TBMQueue. As data is pushed into this sink, it will magically begin to appear in the queue.