1module Control.Distributed.Process.Internal.Spawn
10import Data.Typeable (Typeable)
11import Control.Distributed.Static
17import Control.Distributed.Process.Internal.Types
22 , ProcessMonitorNotification(..)
23 , NodeMonitorNotification(..)
29import Control.Distributed.Process.Serializable (Serializable, SerializableDict)
30import Control.Distributed.Process.Internal.Closure.BuiltIn
42import Control.Distributed.Process.Internal.Primitives
60-- For more information about 'Closure', see
61-- "Control.Distributed.Process.Closure".
64spawn :: NodeId -> Closure (Process ()) -> Process ProcessId
67 mRef <- monitorNode nid
68 sRef <- spawnAsync nid (cpDelay us proc)
70 matchIf (\(DidSpawn ref _) -> ref == sRef) $ \(DidSpawn _ pid) -> do
74 , matchIf (\(NodeMonitorNotification ref _ _) -> ref == mRef) $ \_ ->
75 return (nullProcessId nid)
78-- | Spawn a process and link to it
80-- Note that this is just the sequential composition of 'spawn' and 'link'.
81-- (The "Unified" semantics that underlies Cloud Haskell does not even support
82-- a synchronous link operation)
83spawnLink :: NodeId -> Closure (Process ()) -> Process ProcessId
84spawnLink nid proc = do
89-- | Like 'spawnLink', but monitor the spawned process
90spawnMonitor :: NodeId -> Closure (Process ()) -> Process (ProcessId, MonitorRef)
91spawnMonitor nid proc = do
96-- | Run a process remotely and wait for it to reply
98-- We monitor the remote process: if it dies before it can send a reply, we die
101-- For more information about 'Static', 'SerializableDict', and 'Closure', see
102-- "Control.Distributed.Process.Closure".
105call :: Serializable a
106 => Static (SerializableDict a)
108 -> Closure (Process a)
110call dict nid proc = do
112 (pid, mRef) <- spawnMonitor nid (proc `bindCP` cpSend dict us)
113 -- We are guaranteed to receive the reply before the monitor notification
114 -- (if a reply is sent at all)
115 -- NOTE: This might not be true if we switch to unreliable delivery.
116 mResult <- receiveWait
117 [ match (return . Right)
118 , matchIf (\(ProcessMonitorNotification ref _ _) -> ref == mRef)
119 (\(ProcessMonitorNotification _ _ reason) -> return (Left reason))
123 -- Wait for the monitor message so that we the mailbox doesn't grow
125 [ matchIf (\(ProcessMonitorNotification ref _ _) -> ref == mRef)
126 (\(ProcessMonitorNotification {}) -> return ())
128 -- Clean up connection to pid
132 fail $ "call: remote process died: " ++ show err
134-- | Spawn a child process, have the child link to the parent and the parent
136spawnSupervised :: NodeId
137 -> Closure (Process ())
138 -> Process (ProcessId, MonitorRef)
139spawnSupervised nid proc = do
141 them <- spawn nid (cpLink us `seqCP` proc)
145-- | Spawn a new process, supplying it with a new 'ReceivePort' and return
146-- the corresponding 'SendPort'.
147spawnChannel :: forall a. Typeable a => Static (SerializableDict a)
149 -> Closure (ReceivePort a -> Process ())
150 -> Process (SendPort a)
151spawnChannel dict nid proc = do
153 _ <- spawn nid (go us)
156 go :: ProcessId -> Closure (Process ())
157 go pid = cpNewChan dict
159 (cpSend (sdictSendPort dict) pid `splitCP` proc)
161 (idCP `closureCompose` staticClosure sndStatic)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list