next-ref-0.1.0.2: 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 #

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

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

Create a NextVar

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

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

readLast :: NextRef a -> IO a #

Read the most recent value. Non-blocking

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

Write a new value. Never blocks.

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

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

close :: NextRef a -> IO () #

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

open :: NextRef a -> IO () #

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 #

Get the current status of the NextRef

data Status #

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 
Instances
Bounded Status # 
Instance details

Defined in Control.Concurrent.NextRef

Enum Status # 
Instance details

Defined in Control.Concurrent.NextRef

Eq Status # 
Instance details

Defined in Control.Concurrent.NextRef

Methods

(==) :: Status -> Status -> Bool #

(/=) :: Status -> Status -> Bool #

Ord Status # 
Instance details

Defined in Control.Concurrent.NextRef

Read Status # 
Instance details

Defined in Control.Concurrent.NextRef

Show Status # 
Instance details

Defined in Control.Concurrent.NextRef