Created
March 26, 2014 21:29
-
-
Save tonyday567/9794019 to your computer and use it in GitHub Desktop.
core-cloud.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tRemote :: Int -> IO () | |
tRemote n = do | |
backend0 <- initializeBackend host portSlave rtable | |
node0 <- newLocalNode backend0 | |
backend <- initializeBackend host portMaster rtable | |
node <- newLocalNode backend | |
Node.runProcess node (remotePipe' n (Node.localNodeId node0)) | |
where | |
rtable :: RemoteTable | |
rtable = __remoteTable initRemoteTable | |
remotePipe' :: Int -> NodeId -> Process () | |
remotePipe' n nodeid = do | |
(out0, in0) <- newChan -- main remote channel | |
(outPing, inPing) <- newChan -- ping channel | |
spawnLocal' $ do -- spawnLocal makes sure this is a non-blocking call | |
spawnAsync nodeid (remoteDoublerClosure (outPing, out0)) -- another channel inside the closure | |
_ <- expectTimeout 0 :: Process (Maybe DidSpawn) | |
return () | |
output <- receiveChan inPing -- Wait for remote pipe to send back the output channel details | |
spawnLocal' $ runEffect $ each [1..n] >-> toOutput output -- feeding remote with values | |
runEffect $ fromInput in0 >-> P.take n >-> P.print -- receiving values from remote |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment