expiring-mvar-0.1: Create values which expire after a period of time.

Safe HaskellSafe-Infered

Control.Concurrent.MVar.Expiring

Synopsis

Documentation

data ExpiringMVar a Source

An ExpiringMVar contains a value that will be thrown out after a given period of time. The timer can be reset before the value expires.

newExpiringMVarSource

Arguments

:: a

The value which will expire.

-> Int

The number of microseconds after which the value will expire. Note that the caveats which apply to Control.Concurrent.threadDelay apply to the expiration, also.

-> IO (ExpiringMVar a) 

Create a new value that is set to be thrown away after a minimum period of time. Each call to newExpiringMVar spawns a thread that runs until the value expires.

readExpiringMVar :: ExpiringMVar a -> IO (Maybe a)Source

If the value has not yet expired, you are able to retrieve it. Reading the value does not expire it. In other words, readExpiringMVar behaves like readMVar.

resetExpiringMVarTimer :: ExpiringMVar a -> IO (ExpiringMVar a)Source

If the value has not yet expired, reset the timer. If the value expired, no timer is created.

isExpiredMVar :: ExpiringMVar a -> IO BoolSource

Determine whether an MVar has expired.

cancelExpiration :: ExpiringMVar a -> IO ()Source

If you decide that a value should never expire, you can cancel the timer.

changeExpirationSource

Arguments

:: Int

The new number of milliseconds to set the expiration timer to.

-> ExpiringMVar a 
-> IO (ExpiringMVar a) 

If the value hasn't yet expired, change the timer and reset it.

removeExpiredMVars :: (Monoid (f (ExpiringMVar a)), Alternative f, Traversable t) => t (ExpiringMVar a) -> IO (f (ExpiringMVar a))Source

For a collection of ExpiringMVars, filter out the ones that have expired, and put the remaining ExpiringMVars in a new collection.