Portability | non-portable (GHC STM, DeriveDataTypeable) |
---|---|
Maintainer | Alexander Kondratskiy <kholdstare0.0@gmail.com> |
Safe Haskell | Safe-Inferred |
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
- data TMChunkedQueue a
- data ChunkedQueue a
- consumeQueue :: ChunkedQueue a -> [a]
- newTMChunkedQueue :: STM (TMChunkedQueue a)
- newTMChunkedQueueIO :: IO (TMChunkedQueue a)
- drainTMChunkedQueue :: TMChunkedQueue a -> STM (Maybe (ChunkedQueue a))
- tryDrainTMChunkedQueue :: TMChunkedQueue a -> STM (Maybe (ChunkedQueue a))
- writeTMChunkedQueue :: TMChunkedQueue a -> a -> STM ()
- writeManyTMChunkedQueue :: TMChunkedQueue a -> [a] -> STM ()
- closeTMChunkedQueue :: TMChunkedQueue a -> STM ()
- isEmptyTMChunkedQueue :: TMChunkedQueue a -> STM Bool
- isClosedTMChunkedQueue :: TMChunkedQueue a -> STM Bool
- drainAndSettleTMChunkedQueue :: Int -> TMChunkedQueue a -> IO (Maybe (ChunkedQueue a))
- drainWithTimeoutTMChunkedQueue :: Int -> TMChunkedQueue a -> IO (Maybe (ChunkedQueue a))
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.
Monoid (ChunkedQueue a) |
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
newTMChunkedQueueIO :: IO (TMChunkedQueue a)Source
IO
version of newTMChunkedQueue
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
:: 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
:: 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.