next-ref-0.1.0.0: A concurrency primitive for a slow consumer.

Safe HaskellSafe
LanguageHaskell2010

Control.Concurrent.NextRef

Description

This package contains a concurrency primitive which can be used to limit an expensive consumer from running unnecessarily. Crucially the consumer must be able to tolerate missing some updates.

NextRef provides non-blocking writes, blocking reads, and non-blocking reads.

The blocking read interface (takeNextRef) will not necessarily present all values.

Additionally the NextRef can be closed. This is useful to graceful shutdown the consumer when the producer closes the NextRef

Synopsis

Documentation

data NextRef a Source #

A concurrency primitive for a slow consumer that can tolerate missing some updates.

newNextRef :: a -> IO (NextRef a) Source #

Create a NextVar

takeNextRef :: NextRef a -> IO (Maybe a) Source #

Block until the next value is available. If the NextVar is closed it returns Nothing immediantly.

readLast :: NextRef a -> IO a Source #

Read the most recent value. Non-blocking

writeNextRef :: NextRef a -> a -> IO () Source #

Write a new value. Never blocks.

modifyNextRef :: NextRef a -> (a -> (a, b)) -> IO b Source #

Apply a function to current value to produce the next value and return a result.

close :: NextRef a -> IO () Source #

Modify the status of the NextRef to Closed. All future reads using takeNextRef will result a Nothing. readLast is unaffected.

open :: NextRef a -> IO () Source #

Modify the status of the NextRef to Closed. All future reads using takeNextRef will return a Just. readLast is unaffected.

status :: NextRef a -> IO Status Source #

Get the current status of the NextRef

data Status Source #

Status is used to prevent future reads. When the status is Closed takeNextRef will always return Nothing. When the status is open it will return Just. This is based off of the design of TMQueue from the 'stm-chans' package

Constructors

Open 
Closed