1module Control.Distributed.Process.Internal.Spawn
10import Control.Distributed.Static
16import Control.Distributed.Process.Internal.Types
21 , ProcessMonitorNotification(..)
22 , NodeMonitorNotification(..)
28import Control.Distributed.Process.Serializable (Serializable, SerializableDict)
29import Control.Distributed.Process.Internal.Closure.BuiltIn
41import Control.Distributed.Process.Internal.Primitives
59-- For more information about 'Closure', see
60-- "Control.Distributed.Process.Closure".
63spawn :: NodeId -> Closure (Process ()) -> Process ProcessId
66 mRef <- monitorNode nid
67 sRef <- spawnAsync nid (cpDelay us proc)
69 matchIf (\(DidSpawn ref _) -> ref == sRef) $ \(DidSpawn _ pid) -> do
73 , matchIf (\(NodeMonitorNotification ref _ _) -> ref == mRef) $ \_ ->
74 return (nullProcessId nid)
77-- | Spawn a process and link to it
79-- Note that this is just the sequential composition of 'spawn' and 'link'.
80-- (The "Unified" semantics that underlies Cloud Haskell does not even support
81-- a synchronous link operation)
82spawnLink :: NodeId -> Closure (Process ()) -> Process ProcessId
83spawnLink nid proc = do
88-- | Like 'spawnLink', but monitor the spawned process
89spawnMonitor :: NodeId -> Closure (Process ()) -> Process (ProcessId, MonitorRef)
90spawnMonitor nid proc = do
95-- | Run a process remotely and wait for it to reply
97-- We monitor the remote process: if it dies before it can send a reply, we die
100-- For more information about 'Static', 'SerializableDict', and 'Closure', see
101-- "Control.Distributed.Process.Closure".
104call :: Serializable a
105 => Static (SerializableDict a)
107 -> Closure (Process a)
109call dict nid proc = do
111 (pid, mRef) <- spawnMonitor nid (proc `bindCP` cpSend dict us)
112 -- We are guaranteed to receive the reply before the monitor notification
113 -- (if a reply is sent at all)
114 -- NOTE: This might not be true if we switch to unreliable delivery.
115 mResult <- receiveWait
116 [ match (return . Right)
117 , matchIf (\(ProcessMonitorNotification ref _ _) -> ref == mRef)
118 (\(ProcessMonitorNotification _ _ reason) -> return (Left reason))
122 -- Wait for the monitor message so that we the mailbox doesn't grow
124 [ matchIf (\(ProcessMonitorNotification ref _ _) -> ref == mRef)
125 (\(ProcessMonitorNotification {}) -> return ())
127 -- Clean up connection to pid
131 fail $ "call: remote process died: " ++ show err
133-- | Spawn a child process, have the child link to the parent and the parent
135spawnSupervised :: NodeId
136 -> Closure (Process ())
137 -> Process (ProcessId, MonitorRef)
138spawnSupervised nid proc = do
140 them <- spawn nid (cpLink us `seqCP` proc)
144-- | Spawn a new process, supplying it with a new 'ReceivePort' and return
145-- the corresponding 'SendPort'.
146spawnChannel :: forall a. Serializable a => Static (SerializableDict a)
148 -> Closure (ReceivePort a -> Process ())
149 -> Process (SendPort a)
150spawnChannel dict nid proc = do
152 _ <- spawn nid (go us)
155 go :: ProcessId -> Closure (Process ())
156 go pid = cpNewChan dict
158 (cpSend (sdictSendPort dict) pid `splitCP` proc)
160 (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