git.iko.soy/distributed-process
on fc5d2ad help sign in
32 lines 823 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 spawnLocal (chatty "jim1" lpid1)
18 spawnLocal (chatty "bob1" lpid1)
19 liftIO $ threadDelay 500000
20 return ()
22chatty :: String -> ProcessId -> Process ()
23chatty name target = do
24 send target (name ++ " says: hi there")
25 liftIO $ threadDelay 500000
26 send target (name ++ " says: bye")
28logger :: Int -> Process ()
29logger n = do
30 str <- expect
31 liftIO . putStrLn $ show n ++ ": " ++ str
32 logger (n+1)