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.TChunkedQueue

Contents

Description

A version of Control.Concurrent.STM.TQueue that 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 TChunkedQueue type

data TChunkedQueue a Source

TChunkedQueue is an abstract type representing a 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 TChunkedQueues

newTChunkedQueue :: STM (TChunkedQueue a)Source

Build and returns a new instance of TChunkedQueue

Draining TChunkedQueues

drainTChunkedQueue :: TChunkedQueue a -> STM (ChunkedQueue a)Source

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

tryDrainTChunkedQueue :: TChunkedQueue a -> STM (ChunkedQueue a)Source

Drain everything contained in the TChunkedQueue. Doesn't block

Writing to TChunkedQueues

writeTChunkedQueue :: TChunkedQueue a -> a -> STM ()Source

Write a value to a TChunkedQueue

writeManyTChunkedQueue :: TChunkedQueue a -> [a] -> STM ()Source

Write many values to a TChunkedQueue

Predicates

isEmptyTChunkedQueue :: TChunkedQueue a -> STM BoolSource

Returns True if the supplied TChunkedQueue is empty.

Chunked operations

drainAndSettleTChunkedQueueSource

Arguments

:: Int

settle period in microseconds

-> TChunkedQueue a 
-> IO (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.

drainWithTimeoutTChunkedQueueSource

Arguments

:: Int

timeout in microseconds

-> TChunkedQueue a 
-> IO (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.