@@ -89,6 +89,9 @@ module Control.Distributed.Process
8989 , spawnMonitor
9090 , spawnChannel
9191 , DidSpawn(..)
92+ -- * Local versions of spawn
93+ , spawnLocal
94+ , spawnChannelLocal
9295 ) where
9396
9497
@@ -121,6 +124,7 @@ import Control.Distributed.Process.Internal.Types
121124 , SerializableDict(..)
122125 , SendPortId(..)
123126 , WhereIsReply(..)
127+ , procMsg
124128 )
125129import Control.Distributed.Process.Internal.Closure.CP
126130 ( cpSeq
@@ -190,6 +194,8 @@ import Control.Distributed.Process.Internal.Primitives
190194 , spawnAsync
191195 )
192196import Control.Distributed.Process.Serializable (Serializable)
197+import Control.Distributed.Process.Internal.MessageT (getLocalNode)
198+import Control.Distributed.Process.Node (forkProcess)
193199
194200-- INTERNAL NOTES
195201--
@@ -355,3 +361,24 @@ spawnChannel dict nid proc = do
355361 (cpSend (sdictSendPort dict) pid `cpSplit` proc)
356362 `cpBind`
357363 cpCancelL
364+
365+--------------------------------------------------------------------------------
366+-- Local versions of spawn --
367+--------------------------------------------------------------------------------
368+
369+-- | Spawn a process on the local node
370+spawnLocal :: Process () -> Process ProcessId
371+spawnLocal proc = do
372+ node <- procMsg $ getLocalNode
373+ liftIO $ forkProcess node proc
374+
375+-- | Create a new typed channel, spawn a process on the local node, passing it
376+-- the receive port, and return the send port
377+spawnChannelLocal :: Serializable a
378+ => (ReceivePort a -> Process ())
379+ -> Process (SendPort a)
380+spawnChannelLocal proc = do
381+ node <- procMsg $ getLocalNode
382+ (sport, rport) <- newChan
383+ _ <- liftIO $ forkProcess node (proc rport)
384+ return sport