git.iko.soy/distributed-process
on master help sign in
Bumb version of 0.2.1.3. Add spawnLocal (and co)
648ad93Edsko de Vries
distributed-process/ChangeLog+5
@@ -1,3 +1,8 @@
1+2012-07-20 Edsko de Vries <edsko@well-typed.com> 0.2.1.3
2+
3+* Improve docs
4+* Local versions of spawn
5+
12012-07-16 Edsko de Vries <edsko@well-typed.com> 0.2.1.2
62012-07-16 Edsko de Vries <edsko@well-typed.com> 0.2.1.2
2
7
3* Base 4.6 compatibility
8* Base 4.6 compatibility
distributed-process/distributed-process.cabal+1−1
@@ -1,5 +1,5 @@
1Name: distributed-process
1Name: distributed-process
2−Version: 0.2.1.2
2+Version: 0.2.1.3
3Cabal-Version: >=1.8
3Cabal-Version: >=1.8
4Build-Type: Simple
4Build-Type: Simple
5License: BSD3
5License: BSD3
distributed-process/src/Control/Distributed/Process.hs+27
@@ -89,6 +89,9 @@ module Control.Distributed.Process
89 , spawnMonitor
89 , spawnMonitor
90 , spawnChannel
90 , spawnChannel
91 , DidSpawn(..)
91 , DidSpawn(..)
92+ -- * Local versions of spawn
93+ , spawnLocal
94+ , spawnChannelLocal
92 ) where
95 ) where
93
96
94
97
@@ -121,6 +124,7 @@ import Control.Distributed.Process.Internal.Types
121 , SerializableDict(..)
124 , SerializableDict(..)
122 , SendPortId(..)
125 , SendPortId(..)
123 , WhereIsReply(..)
126 , WhereIsReply(..)
127+ , procMsg
124 )
128 )
125import Control.Distributed.Process.Internal.Closure.CP
129import Control.Distributed.Process.Internal.Closure.CP
126 ( cpSeq
130 ( cpSeq
@@ -190,6 +194,8 @@ import Control.Distributed.Process.Internal.Primitives
190 , spawnAsync
194 , spawnAsync
191 )
195 )
192import Control.Distributed.Process.Serializable (Serializable)
196import Control.Distributed.Process.Serializable (Serializable)
197+import Control.Distributed.Process.Internal.MessageT (getLocalNode)
198+import Control.Distributed.Process.Node (forkProcess)
193
199
194-- INTERNAL NOTES
200-- INTERNAL NOTES
195--
201--
@@ -355,3 +361,24 @@ spawnChannel dict nid proc = do
355 (cpSend (sdictSendPort dict) pid `cpSplit` proc)
361 (cpSend (sdictSendPort dict) pid `cpSplit` proc)
356 `cpBind`
362 `cpBind`
357 cpCancelL
363 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
distributed-process/tests/TestCH.hs+19
@@ -560,6 +560,24 @@ testRemoteRegistry transport = do
560 True <- return $ pingServer == pid'
560 True <- return $ pingServer == pid'
561 return ()
561 return ()
562
562
563+testSpawnLocal :: NT.Transport -> IO ()
564+testSpawnLocal transport = do
565+ node <- newLocalNode transport initRemoteTable
566+
567+ runProcess node $ do
568+ us <- getSelfPid
569+
570+ pid <- spawnLocal $ do
571+ sport <- expect
572+ sendChan sport (1234 :: Int)
573+
574+ sport <- spawnChannelLocal $ \rport -> do
575+ (1234 :: Int) <- receiveChan rport
576+ send us ()
577+
578+ send pid sport
579+ expect
580+
563main :: IO ()
581main :: IO ()
564main = do
582main = do
565 Right transport <- createTransport "127.0.0.1" "8080" defaultTCPParameters
583 Right transport <- createTransport "127.0.0.1" "8080" defaultTCPParameters
@@ -574,6 +592,7 @@ main = do
574 , ("Terminate", testTerminate transport)
592 , ("Terminate", testTerminate transport)
575 , ("Registry", testRegistry transport)
593 , ("Registry", testRegistry transport)
576 , ("RemoteRegistry", testRemoteRegistry transport)
594 , ("RemoteRegistry", testRemoteRegistry transport)
595+ , ("SpawnLocal", testSpawnLocal transport)
577 -- Monitoring processes
596 -- Monitoring processes
578 --
597 --
579 -- The "missing" combinations in the list below don't make much sense, as
598 -- The "missing" combinations in the list below don't make much sense, as