git.iko.soy/distributed-process
on fdcb722 help sign in
36 lines 965 B history raw
1module DemoProcess where
3import Control.Distributed.Process
4import Control.Concurrent (threadDelay)
6import Network.Transport.TCP (mkTransport, TCPConfig (..))
8import Debug.Trace
10demo1 = do
11 trans <- mkTransport $ TCPConfig undefined "127.0.0.1" "8080"
12 node <- newLocalNode trans
13 print "Starting node"
14 runProcess node $ do
15 liftIO $ print "Starting process"
16 lpid1 <- spawnLocal (logger 1)
17-- liftIO $ print "baz"
18-- lpid2 <- spawnLocal (logger 2)
19 spawnLocal (chatty "jim1" lpid1)
20-- spawnLocal (chatty "jim2" lpid2)
21 spawnLocal (chatty "bob1" lpid1)
22-- spawnLocal (chatty "bob2" lpid2)
23 liftIO $ threadDelay 500000
24 return ()
26chatty :: String -> ProcessId -> Process ()
27chatty name target = do
28 send target (name ++ " says: hi there")
29 liftIO $ threadDelay 500000
30 send target (name ++ " says: bye")
32logger :: Int -> Process ()
33logger n = do
34 str <- expect
35 liftIO . putStrLn $ show n ++ ": " ++ str
36 logger (n+1)