flush-queue-1.0.0: Concurrent bouded blocking queues optimized for flushing. Both IO and STM implementations.

Copyright(c) FP Complete 2018
LicenseBSD3
MaintainerAlexey Kuleshevich <alexey@fpcomplete.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Control.Concurrent.STM.TBFQueue

Description

Transactional Bouded Flush Queue is a very similar to BFQueue, with an exception that it runs in STM and is also less efficient, but is still faster than TBQueue.

Synopsis

Documentation

data TBFQueue a Source #

Bounded Flush Queue. It's a queue that allows pushing elements onto, popping elements from it, but is mostly optimizied for flushing the queue or taking in bulk.

newTBFQueue Source #

Arguments

:: Natural

Maximum number of elements, that this queue can hold.

-> STM (TBFQueue a) 

Construct a new empty Flush Bounded Queue

newTBFQueueIO Source #

Arguments

:: Natural

Maximum number of elements, that this queue can hold.

-> IO (TBFQueue a) 

Construct a new empty Flush Bounded Queue inside IO monad.

writeTBFQueue :: TBFQueue a -> a -> STM () Source #

O(1) - Push an element onto the queue. Will block if maximum bound has been reached.

tryWriteTBFQueue :: TBFQueue a -> a -> STM Bool Source #

O(1) - Try to push an element onto the queue without blocking. Will return True if element was pushed successfully, and False in case when the queue is full.

readTBFQueue :: TBFQueue a -> STM a Source #

Amortized O(1) - Pop an element from the queue. Will block if queue is empty.

takeTBFQueue :: Natural -> TBFQueue a -> STM [a] Source #

O(i) - Take i elements from the queue, unblock all the possible writers and return all the elements from the queue in FIFO order.

flushTBFQueue :: TBFQueue a -> STM [a] Source #

O(n) - Flush the queue, unblock all the possible writers and return all the elements from the queue in FIFO order.

lengthTBFQueue :: TBFQueue a -> STM Natural Source #

O(1) - Extract number of elements that is currently on the queue

isEmptyTBFQueue :: TBFQueue a -> STM Bool Source #

O(1) - Check if queue is empty