{-# LANGUAGE TemplateHaskell, DeriveDataTypeable, DeriveGeneric #-} {-# OPTIONS_GHC -Wall #-} import Control.Distributed.Process import Control.Distributed.Process.Closure import Control.Monad import Text.Printf import GHC.Generics (Generic) import Data.Binary import Data.Typeable import DistribUtils -- <> -- <> -- <> -- < Process () -- <1> master peers = do ps <- forM peers $ \nid -> do -- <2> say $ printf "spawning on %s" (show nid) spawn nid $(mkStaticClosure 'pingServer) mapM_ monitor ps mypid <- getSelfPid ports <- forM ps $ \pid -> do say $ printf "pinging %s" (show pid) (sendport,recvport) <- newChan send pid (Ping sendport) return recvport let loop [] = return () loop (port:ps) = do receiveWait [ match $ \(ProcessMonitorNotification ref pid reason) -> do say (show pid ++ " died: " ++ show reason) loop (port:ps) , matchChan port $ \p -> do say "pong on channel" loop ps ] loop ports say "All pongs successfully received" terminate -- >> -- <
>