sync-mht-0.3.8.0: Fast incremental file transfer using Merkle-Hash-Trees

Safe HaskellNone
LanguageHaskell2010

Sync.MerkleTree.Util.RequestMonad

Description

This monad is used to increase the speed of communication between two processes - if there is latency. It works by using the non-deterministic part of the communication protocol to send multiple requests to the output-channel, before processing the responses from the input-channel.

Considering the example

foo = splitRequests [bar, baz]
bar = do x <- request (GetSumOf 1 2)
         liftM Sum request (GetSumOf x 3)
baz = liftM Sum request (GetSumOf 4 5)

running foo in the RequestMonad:

runRequestMonad inputHandle outputHandle foo

will send both messages GetSumOf 1 2, GetSumOf 4 5, without having to wait for the repsonse to the first request. The last request GetSumOf 3 3 will be send after the response for the first message has arrived.

Synopsis

Documentation

runRequestMonad :: InputStream ByteString -> OutputStream ByteString -> RequestMonad b -> IO b Source

Run the provided request monad using the given communication channels

splitRequests :: Monoid a => [RequestMonad a] -> RequestMonad a Source

Combine results in the monad non-deterministically (it is required that the monoid is commutative)