git.iko.soy/distributed-process
on master help sign in
Modify example for TCP.
fdcb722Nicolas Wu
examples/DemoProcess.hs+7−6
@@ -3,18 +3,19 @@ module DemoProcess where
3import Control.Distributed.Process
3import Control.Distributed.Process
4import Control.Concurrent (threadDelay)
4import Control.Concurrent (threadDelay)
5
5
6−import Network.Transport.MVar (mkTransport)
6+import Network.Transport.TCP (mkTransport, TCPConfig (..))
7+
8+import Debug.Trace
7
9
8demo1 = do
10demo1 = do
9− trans <- mkTransport
11+ trans <- mkTransport $ TCPConfig undefined "127.0.0.1" "8080"
10 node <- newLocalNode trans
12 node <- newLocalNode trans
11− print "foo"
13+ print "Starting node"
12 runProcess node $ do
14 runProcess node $ do
13− liftIO $ print "bar"
15+ liftIO $ print "Starting process"
14 lpid1 <- spawnLocal (logger 1)
16 lpid1 <- spawnLocal (logger 1)
15-- liftIO $ print "baz"
17-- liftIO $ print "baz"
16-- lpid2 <- spawnLocal (logger 2)
18-- lpid2 <- spawnLocal (logger 2)
17−
18 spawnLocal (chatty "jim1" lpid1)
19 spawnLocal (chatty "jim1" lpid1)
19-- spawnLocal (chatty "jim2" lpid2)
20-- spawnLocal (chatty "jim2" lpid2)
20 spawnLocal (chatty "bob1" lpid1)
21 spawnLocal (chatty "bob1" lpid1)
@@ -31,5 +32,5 @@ chatty name target = do
31logger :: Int -> Process ()
32logger :: Int -> Process ()
32logger n = do
33logger n = do
33 str <- expect
34 str <- expect
34− liftIO $ putStrLn $ show n ++ ": " ++ str
35+ liftIO . putStrLn $ show n ++ ": " ++ str
35 logger (n+1)
36 logger (n+1)