AVar-0.0.5.1: Mutable variables with Exception handling and concurrency support.

Data.AVar.Unsafe

Description

Data.AVar.Unsafe has a similar interface to Data.AVar, but instead of letting the user handle exceptions from Eithers, it will throw exceptions caught by the variable.

Synopsis

Documentation

data AVar a Source

AVars are the means through which communication with the variable are conducted. They contain a Chan that is connected to the variable, and is read by the variable's handler function.

data Result Source

Constructors

OK 

getAVar :: AVar a -> IO aSource

getAVar reads the current value inside the AVar.

putAVar :: AVar a -> a -> IO ()Source

putAVar replaces the currect value in the variable with the given x

modAVar :: AVar a -> (a -> a) -> IO ()Source

modAVar takes a function from a to a, and modifies the variable. It will throw any exceptions caught by the variable when applying the function.

modAVar' :: AVar a -> (a -> (a, b)) -> IO bSource

modAVar' is like modAVar, but it modifies the variable, along with returning a result of type b. It also throws any errors caugh by the variable.

justModAVar :: AVar a -> (a -> a) -> IO ()Source

justModAVar will attempt to run the given function on the variable. It does not report back on its sucess or failure, and if the function produces an exception, the variable is left unchanged. It should be used when you just want to modify the variable, and keep running, without waiting for the action to complete.

condModAVar :: AVar a -> (a -> Bool) -> (a -> a) -> (a -> a) -> IO BoolSource

condModAVar applies the first finction to the current value in the AVar, and will modify the value using the second function if it results in True, or the third function if it results in Fasle.

swapAVar :: AVar a -> a -> IO aSource

swapAVar takes a new value, puts it into the AVar, and returns the old value.

newAVar :: a -> IO (AVar a)Source

newAVar creates a new variable. It forks off the handler that does the work for the variable itself and creates a new AVar.