stm-chunked-queues-0.1.0.0: Chunked Communication Queues

Portabilitynon-portable (GHC STM, DeriveDataTypeable)
MaintainerAlexander Kondratskiy <kholdstare0.0@gmail.com>
Safe HaskellSafe-Inferred

Control.Concurrent.STM.TMChunkedQueue

Contents

Description

A version of Control.Concurrent.STM.TQueue where the queue is closeable and allows complete draining. This makes it possible to chunk items based on a timeout or a settle period. This is useful when items/requests arriving through the queue are too granular and have to be combined, while retaining responsiveness.

Some capabilities of TQueue are missing (such as unget) due to design tradeoffs.

Since: 0.1.0

Synopsis

The TMChunkedQueue type

data TMChunkedQueue a Source

TMChunkedQueue is an abstract type representing a closeable, drainable FIFO queue.

data ChunkedQueue a Source

Abstract type representing a chunked queue. Acts as API for drainining queues.

Instances

consumeQueue :: ChunkedQueue a -> [a]Source

Consume a ChunkedQueue into a list

Creating TMChunkedQueues

newTMChunkedQueue :: STM (TMChunkedQueue a)Source

Build and returns a new instance of TMChunkedQueue

Draining TMChunkedQueues

drainTMChunkedQueue :: TMChunkedQueue a -> STM (Maybe (ChunkedQueue a))Source

Drain everything contained in the TMChunkedQueue, but block if it is empty. Corollary: never returns empty queue.

  • Closed, Empty - Nothing * Closed, Non-Empty - Just [...] * Open, Empty - Blocks * Open, Non-Empty - Just [...]

tryDrainTMChunkedQueue :: TMChunkedQueue a -> STM (Maybe (ChunkedQueue a))Source

Drain everything contained in the TMChunkedQueue. Doesn't block.

  • Closed, Empty - Nothing * Closed, Non-Empty - Just [...] * Open, Empty - Just [] * Open, Non-Empty - Just [...]

Writing to TMChunkedQueues

writeTMChunkedQueue :: TMChunkedQueue a -> a -> STM ()Source

Write a value to a TMChunkedQueue

writeManyTMChunkedQueue :: TMChunkedQueue a -> [a] -> STM ()Source

Write many values to a TMChunkedQueue

Closing TMChunkedQueues

closeTMChunkedQueue :: TMChunkedQueue a -> STM ()Source

Closes the TMQueue, preventing any further writes.

Predicates

isEmptyTMChunkedQueue :: TMChunkedQueue a -> STM BoolSource

Returns True if the supplied TMChunkedQueue is empty.

isClosedTMChunkedQueue :: TMChunkedQueue a -> STM BoolSource

Returns True if the supplied TMChunkedQueue has been closed.

Chunked operations

drainAndSettleTMChunkedQueueSource

Arguments

:: Int

settle period in microseconds

-> TMChunkedQueue a 
-> IO (Maybe (ChunkedQueue a)) 

Keep draining the queue until no more items are seen for at least the given timeout period. Blocks if the queue is empty to begin with, and starts timing after the first value appears in the queue.

drainWithTimeoutTMChunkedQueueSource

Arguments

:: Int

timeout in microseconds

-> TMChunkedQueue a 
-> IO (Maybe (ChunkedQueue a)) 

Keep draining the queue for at least the specified time period. Blocks if the queue is empty to begin with, and starts timing as soon as the first value appears in the queue.