| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
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
- data NextRef a
- newNextRef :: a -> IO (NextRef a)
- takeNextRef :: NextRef a -> IO (Maybe a)
- readLast :: NextRef a -> IO a
- writeNextRef :: NextRef a -> a -> IO ()
- modifyNextRef :: NextRef a -> (a -> (a, b)) -> IO b
- close :: NextRef a -> IO ()
- open :: NextRef a -> IO ()
- status :: NextRef a -> IO Status
- data Status
Documentation
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.
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 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.