Skip to content

Instantly share code, notes, and snippets.

@tonyday567
Created March 26, 2014 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyday567/9794019 to your computer and use it in GitHub Desktop.
Save tonyday567/9794019 to your computer and use it in GitHub Desktop.
core-cloud.hs
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