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