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