Portability | non-portable (GHC STM, DeriveDataTypeable) |
---|---|
Maintainer | Alexander Kondratskiy <kholdstare0.0@gmail.com> |
Safe Haskell | Safe-Inferred |
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
- data TChunkedQueue a
- data ChunkedQueue a
- consumeQueue :: ChunkedQueue a -> [a]
- newTChunkedQueue :: STM (TChunkedQueue a)
- newTChunkedQueueIO :: IO (TChunkedQueue a)
- drainTChunkedQueue :: TChunkedQueue a -> STM (ChunkedQueue a)
- tryDrainTChunkedQueue :: TChunkedQueue a -> STM (ChunkedQueue a)
- writeTChunkedQueue :: TChunkedQueue a -> a -> STM ()
- writeManyTChunkedQueue :: TChunkedQueue a -> [a] -> STM ()
- isEmptyTChunkedQueue :: TChunkedQueue a -> STM Bool
- drainAndSettleTChunkedQueue :: Int -> TChunkedQueue a -> IO (ChunkedQueue a)
- drainWithTimeoutTChunkedQueue :: Int -> TChunkedQueue a -> IO (ChunkedQueue a)
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.
Monoid (ChunkedQueue a) |
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
newTChunkedQueueIO :: IO (TChunkedQueue a)Source
IO
version of newTChunkedQueue
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
:: 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
:: 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.