module Control.Distributed.Process.Node.Lifted
( module Control.Distributed.Process.Node.Lifted
, Base.LocalNode
, Base.initRemoteTable
, Base.localNodeId
) where
import Control.Monad.Base ( MonadBase, liftBase )
import Control.Monad (void)
import Control.Distributed.Process (ProcessId, Process, RemoteTable)
import Control.Distributed.Process.Node (LocalNode)
import Control.Exception (throw, SomeException)
import Control.Exception.Lifted (try)
import Network.Transport (Transport)
import qualified Control.Distributed.Process.Node as Base
import Control.Concurrent.MVar.Lifted
(newEmptyMVar, putMVar, takeMVar)
import Control.Distributed.Process.MonadBaseControl ()
import Control.DeepSeq (NFData, deepseq)
closeLocalNode :: MonadBase IO m => LocalNode -> m ()
closeLocalNode = liftBase . Base.closeLocalNode
forkProcess :: MonadBase IO m => LocalNode -> Process () -> m ProcessId
forkProcess n = liftBase . Base.forkProcess n
newLocalNode :: MonadBase IO m => Transport -> RemoteTable -> m LocalNode
newLocalNode t = liftBase . Base.newLocalNode t
runProcess :: MonadBase IO m => LocalNode -> Process () -> m ()
runProcess n = liftBase . Base.runProcess n
fromProcess :: forall a m. (NFData a, MonadBase IO m)
=> LocalNode -> Process a -> m a
fromProcess node ma =
do resultMV <- newEmptyMVar
void . forkProcess node $
do eresult <- try (do a <- ma; a `deepseq` return a) :: Process (Either SomeException a)
case eresult of
Right result -> putMVar resultMV result
Left exception -> putMVar resultMV (throw exception)
!result <- takeMVar resultMV
return result