ring-buffer-0.1.2: A concurrent, mutable ring-buffer

Safe HaskellNone
LanguageHaskell2010

Data.RingBuffer

Description

This is a thread-safe implementation of a mutable ring-buffer built upon vector.

Synopsis

Documentation

data RingBuffer v a Source

A concurrent ring buffer.

new :: Vector v a => Int -> IO (RingBuffer v a) Source

Create a new ring of a given length

clear :: Vector v a => RingBuffer v a -> IO () Source

Reset the ringbuffer to its empty state

append :: Vector v a => a -> RingBuffer v a -> IO () Source

Add an item to the end of the ring

concat :: Vector v a => v a -> RingBuffer v a -> IO () Source

Add multiple items to the end of the ring This ignores any items above the length of the ring

capacity :: Vector v a => RingBuffer v a -> Int Source

The maximum number of items the ring can contain

length :: Vector v a => RingBuffer v a -> IO Int Source

The current filled length of the ring

withItems :: (MonadIO m, Vector v a) => RingBuffer v a -> (v a -> m b) -> m b Source

Execute the given action with the items of the ring. Note that no references to the vector may leak out of the action as it will later be mutated. Moreover, the items in the vector are in no particular order.