Skip to content

Instantly share code, notes, and snippets.

@tonyday567
Created March 26, 2014 21:29
Show Gist options
  • Select an option

  • Save tonyday567/9794019 to your computer and use it in GitHub Desktop.

Select an option

Save tonyday567/9794019 to your computer and use it in GitHub Desktop.

Revisions

  1. tonyday567 created this gist Mar 26, 2014.
    22 changes: 22 additions & 0 deletions core-cloud.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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