-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bounded channel for STM that discards old entries when full -- -- This package provides a FIFO channel for STM supporting a size limit. -- When this limit is reached, older entries are discarded to make way -- for newer entries. -- -- The motivation for this is logging. If log entries are written to a -- plain TChan, the program will use a lot of memory if it -- produces log entries faster than they can be processed. If log entries -- are written to a bounded channel where writes block (e.g. the -- stm-chans package), the program may deadlock if the log -- channel fills up. With Data.STM.RollingQueue, old entries will -- be discarded instead. -- -- Possible improvements (not available in Data.STM.RollingQueue) -- include: -- -- @package rolling-queue @version 0.1 -- | This module is usually imported qualified: -- --
--   import Data.STM.RollingQueue (RollingQueue)
--   import qualified Data.STM.RollingQueue as RQ
--   
module Data.STM.RollingQueue -- | A RollingQueue is a bounded FIFO channel. When the size limit -- is exceeded, older entries are discarded to make way for newer -- entries. -- -- Note: if the size limit is less than 1, write will -- have no effect, and read will always retry. data RollingQueue a -- | Create a new, empty RollingQueue, with the given size limit. -- -- To change the size limit later, use setLimit. new :: Int -> STM (RollingQueue a) -- | IO variant of new. This is useful for creating -- top-level RollingQueues using unsafePerformIO, because -- performing atomically inside a pure computation is extremely -- dangerous (can lead to NestedAtomically errors and even -- segfaults, see GHC ticket #5866). -- -- Example: -- --
--   logQueue :: RollingQueue LogEntry
--   logQueue = unsafePerformIO (RQ.newIO 1000)
--   {-# NOINLINE logQueue #-}
--   
newIO :: Int -> IO (RollingQueue a) -- | Write an entry to the rolling queue. If the queue is full, discard the -- oldest entry. -- -- There is no tryWrite, because write never retries. write :: RollingQueue a -> a -> STM () -- | Read the next entry from the RollingQueue. retry if the -- queue is empty. -- -- The Int is the number of entries discarded since the last read -- operation (usually 0). read :: RollingQueue a -> STM (a, Int) -- | Like read, but do not retry. Instead, return -- Nothing if the queue is empty. tryRead :: RollingQueue a -> STM (Maybe (a, Int)) -- | Test if the queue is empty. isEmpty :: RollingQueue a -> STM Bool -- | O(1) Get the number of items in the queue. length :: RollingQueue a -> STM Int -- | Adjust the size limit. Queue entries will be discarded if necessary to -- satisfy the new limit. setLimit :: RollingQueue a -> Int -> STM () -- | Get the current size limit. This will return 0 if a negative value was -- passed to new, newIO, or setLimit. getLimit :: RollingQueue a -> STM Int -- | Verify internal structure. Throw a CheckException if the check -- fails, signifying a bug in the implementation. checkInvariants :: RollingQueue a -> STM () data CheckException CheckException :: String -> CheckException -- | Dump the RollingQueue (output and internal counters) to standard -- output. This calls checkInvariants first. dump :: Show a => RollingQueue a -> IO () instance Typeable1 RollingQueue instance Typeable CheckException instance Exception CheckException instance Show CheckException instance Eq (RollingQueue a)