net-concurrent-0.1.0: Concurrent over the network execution library

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.

Synopsis

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.

tryPutNVar :: Binary a => NCContext -> String -> a -> IO BoolSource

Tries to put a value into NVar specified by the name. If the NVar doesn't exist returns IO False.

If the NVar already has a value returns IO False and leaves the value untouched.

If the NVar is empty this sets it to the specified value and returns IO True.

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.

readNVar :: Binary a => NCContext -> String -> IO aSource

Like with MVars this takes an NVar put's the taken value back, and returns it.

pollWithOp :: Binary a => NCContext -> String -> Equality -> a -> IO ()Source

Polls while the given condition is true for NVar called name. As this call doesn't return while the condition is true, it's much more efficient than busy waiting in the slave generating network traffic.