Control.Concurrent.Network.NVar
Contents
Description
Network variables.
Communication is done by using NVar variables similar to MVar in Concurrent.
Every read and every write results in network transaction with the master process, so handle with care.
This is done with a push style implementation so putNVar propagets the value to
the master process, but other slaves won't get automatically notified
about the change. The next takeNVar will result in the updated value.
To save network bandwith and load on the master, it is possible to wait for an
NVar to change value using pollWithOp.
- newNVar :: NCContext -> String -> IO ()
- putNVar :: Binary a => NCContext -> String -> a -> IO ()
- takeNVar :: Binary a => NCContext -> String -> IO a
- tryPutNVar :: Binary a => NCContext -> String -> a -> IO Bool
- tryTakeNVar :: Binary a => NCContext -> String -> IO (Maybe a)
- readNVar :: Binary a => NCContext -> String -> IO a
- pollWithOp :: Binary a => NCContext -> String -> Equality -> a -> IO ()
Functions
newNVar :: NCContext -> String -> IO ()Source
Creates a new empty NVar on the master. Doesn't block the caller.
putNVar :: Binary a => NCContext -> String -> a -> IO ()Source
Puts a value into NVar specified by the name.
If the NVar doesn't exist this blocks the caller until it's
created potentially by an other slave.
If the NVar already has a value this blocks the caller until
an other slave calls takeNVar.
If the NVar is empty this returns immediately after the network
transactions.
takeNVar :: Binary a => NCContext -> String -> IO aSource
Takes the latest value of NVar from the master.
If the NVar doesn't exist this blocks the caller until it's
created potentially by an other slave.
If the NVar is empty this blocks the caller until
an other slave calls putNVar.
If the NVar has a value this returns immediately after the network
transactions.
tryTakeNVar :: Binary a => NCContext -> String -> IO (Maybe a)Source
Takes the latest value of NVar from the master.
If the NVar doesn't exist this blocks the caller until it's
created potentially by an other slave.
If the NVar is empty this blocks the caller until
an other slave calls putNVar.
If the NVar has a value this returns immediately after the network
transactions.