kickchan-0.1.0.4: Kick Channels: bounded channels with non-blocking writes

Safe HaskellNone

Chan.KickChan

Contents

Synopsis

Kick Channels

data KickChan v a Source

A Channel that drops elements from the end when a KCReader lags too far behind the writer.

Creation

newKickChan :: (MVector v' a, v ~ v' RealWorld) => Int -> IO (KickChan v a)Source

Create a new KickChan of the requested size. The actual size will be rounded up to the next highest power of 2. The stored size will have one subtracted, because that's the value we use for masking, which is the most common operation.

kcSize :: KickChan v a -> IntSource

Get the size of a KickChan.

Writing

putKickChan :: (MVector v' a, v ~ v' RealWorld) => KickChan v a -> a -> IO ()Source

Put a value into a KickChan.

if there are multiple writers, putKickChan may block if one writer has wrapped around and a write is pending to the underlying storage location.

putKickChan will never block on readers, instead KCReaders will be invalidated if they lag too far behind.

invalidateKickChan :: KickChan v a -> IO ()Source

Invalidate all current readers on a channel.

Reading

data KCReader v a Source

A reader for a KickChan

newReader :: KickChan v a -> IO (KCReader v a)Source

create a new reader for a KickChan. The reader will be initialized to the head of the KickChan, so that an immediate call to readNext will block (provided no new values have been put into the chan in the meantime).

readNext :: (MVector v' a, v ~ v' RealWorld) => KCReader v a -> IO (Maybe a)Source

get the next value from a KCReader. This function will block if the next value is not yet available.

if Nothing is returned, the reader has lagged the writer and values have been dropped.

currentLag :: KCReader v a -> IO IntSource

The lag between a KCReader and its writer. Mostly useful for determining if a call to readNext will block.

type constraint helpers

kcUnboxed :: KickChan (MVector RealWorld) a -> KickChan (MVector RealWorld) aSource

Constrain a KickChan to work with an Unboxed data storage

kcStorable :: KickChan (MVector RealWorld) a -> KickChan (MVector RealWorld) aSource

Constrain a KickChan to work with a Storable data storage

kcDefault :: KickChan (MVector RealWorld) a -> KickChan (MVector RealWorld) aSource

Constrain a KickChan to work with a standard boxed vector data storage