ivar-simple-0.3.3: Write once concurrency primitives.

Copyright(c) 2008-2020 Bertram Felgenhauer
LicenseMIT
MaintainerBertram Felgenhauer <int-e@gmx.de>
Stabilityexperimental
Portabilityghc
Safe HaskellNone
LanguageHaskell2010

Data.IVar.Simple

Description

IVars are write-once variables.

Similarily to MVars, IVars can be either empty or filled. Once filled, they keep their value indefinitely - they are immutable.

Reading from an empty IVar will block until the IVar is filled. Because the value read will never change, this is a pure computation.

Synopsis

Documentation

data IVar a Source #

A write-once (immutable) Variable

Instances
Eq (IVar a) Source # 
Instance details

Defined in Data.IVar.Simple

Methods

(==) :: IVar a -> IVar a -> Bool #

(/=) :: IVar a -> IVar a -> Bool #

new :: IO (IVar a) Source #

Create a new, empty IVar.

newFull :: a -> IO (IVar a) Source #

Create a new filled IVar.

This is slightly cheaper than creating a new IVar and then writing to it.

read :: IVar a -> a Source #

Returns the value of an IVar.

The evaluation will block until a value is written to the IVar if it has no value yet.

tryRead :: IVar a -> IO (Maybe a) Source #

Try to read an IVar. Returns Nothing if it has no value yet.

write :: IVar a -> a -> IO () Source #

Writes a value to an IVar. Raises a BlockedIndefinitelyOnIVar exception if the variable already has a value.

tryWrite :: IVar a -> a -> IO Bool Source #

Writes a value to an IVar. Returns True if successful, and False otherwise.