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

Safe HaskellNone

Data.Conduit.Async

Description

  • Introduction

Contains a combinator for concurrently joining a producer and a consumer, such that the producer may continue to produce (up to the queue size) as the consumer is concurrently consuming.

Synopsis

Documentation

buffer :: (MonadBaseControl IO m, MonadIO m) => Int -> Producer m a -> Consumer a m b -> m bSource

Concurrently join the producer and consumer, using a bounded queue of the given size. The producer will block when the queue is full, if it is producing faster than the consumers is taking from it. Likewise, if the consumer races ahead, it will block until more input is available.

Exceptions are properly managed and propagated between the two sides, so the net effect should be equivalent to not using buffer at all, save for the concurrent interleaving of effects.

($$&) :: (MonadIO m, MonadBaseControl IO m) => Producer m a -> Consumer a m b -> m bSource

An operator form of buffer. In general you should be able to replace any use of $$ with $$& and suddenly reap the benefit of concurrency, if your conduits were spending time waiting on each other.

bufferToFileSource

Arguments

:: (MonadBaseControl IO m, MonadIO m, MonadResource m, Serialize a) 
=> Int

Size of the bounded queue in memory

-> Maybe Int

Max elements to keep on disk at one time

-> FilePath

Directory to write temp files to

-> Producer m a 
-> Consumer a m b 
-> m b 

Like buffer, except that when the bounded queue is overflowed, the excess is cached in a local file so that consumption from upstream may continue. When the queue becomes exhausted by yielding, it is filled from the cache until all elements have been yielded.

Note that the maximum amount of memory consumed is equal to (2 * memorySize + 1), so take this into account when picking a chunking size.

gatherFromSource

Arguments

:: (MonadIO m, MonadBaseControl IO m) 
=> Int

Size of the queue to create

-> (TBQueue o -> m ())

Action that generates output values

-> Producer m o 

Gather output values asynchronously from an action in the base monad and then yield them downstream. This provides a means of working around the restriction that ConduitM cannot be an instance of MonadBaseControl in order to, for example, yield values from within a Haskell callback function called from a C library.

drainToSource

Arguments

:: (MonadIO m, MonadBaseControl IO m) 
=> Int

Size of the queue to create

-> (TBQueue (Maybe i) -> m r)

Action to consume input values

-> Consumer i m r 

Drain input values into an asynchronous action in the base monad via a bounded TBQueue. This is effectively the dual of gatherFrom.