Safe Haskell | None |
---|---|
Language | Haskell2010 |
WVar is waitable IORef
.
It is similar to MVar
but different at some points.
- The latest (cached) value can be read while someone is updating the value.
- Put operation can overwrite the value if the value is fresh and cannot be blocked for waiting empty.
- WVar is strict. It means that the new value storing into the WVar will be evaluated (WHNF) before actual storing.
There are two states in the user viewpoint.
- data WVar a
- newWVar :: a -> IO (WVar a)
- takeWVar :: WVar a -> IO a
- tryTakeWVar :: WVar a -> IO (Bool, a)
- putWVar :: WVar a -> a -> IO ()
- readWVar :: WVar a -> IO a
- readFreshWVar :: WVar a -> IO a
- tryReadFreshWVar :: WVar a -> IO (Bool, a)
- data WCached a = WCached {
- cachedVar :: !(WVar a)
- cachedTicket :: WTicket a
- type WTicket a = Ticket (WContent a)
- cacheWVar :: WVar a -> IO (WCached a)
- recacheWCached :: WCached a -> IO (WCached a)
- readWTicket :: WTicket a -> a
- takeWCached :: WCached a -> IO (WTicket a)
- tryTakeWCached :: WCached a -> IO (Bool, WTicket a)
- putWCached :: WCached a -> a -> IO (WTicket a)
- tryPutWCached :: WCached a -> a -> IO (Bool, WTicket a)
- readWCached :: WCached a -> a
- readFreshWCached :: WCached a -> IO (WTicket a)
- tryReadFreshWCached :: WCached a -> IO (Bool, WTicket a)
WVar
readFreshWVar :: WVar a -> IO a Source
tryReadFreshWVar :: WVar a -> IO (Bool, a) Source
Non-blocking version of readFreshWVar
WCached
Low level types and functions of WVar
.
WCached consists of WVar and its cached ticket.
WCached | |
|
recacheWCached :: WCached a -> IO (WCached a) Source
Recache the WCached
.
recacheWCached = cacheWVar . cachedVar
readWTicket :: WTicket a -> a Source
Read the value of the WTicket
takeWCached :: WCached a -> IO (WTicket a) Source
tryTakeWCached :: WCached a -> IO (Bool, WTicket a) Source
Non-blocking version of takeWCached
.
putWCached :: WCached a -> a -> IO (WTicket a) Source
readWCached :: WCached a -> a Source
Read the cached value of the WCached
. It never blocks.
readFreshWCached :: WCached a -> IO (WTicket a) Source
tryReadFreshWCached :: WCached a -> IO (Bool, WTicket a) Source
Non-blocking version of readFreshWCached