module Control.Distributed.Fork
( fork,
initDistributedFork,
Backend,
Handle,
await,
pollHandle,
ExecutorStatus (..),
ExecutorPendingStatus (..),
ExecutorFinalStatus (..),
ExecutorFailedException (..),
Serializable,
Closure,
cap,
cpure,
Dict (Dict),
)
where
import Control.Distributed.Closure
import Control.Distributed.Fork.Internal
import Control.Monad
import Control.Monad.Catch
import Control.Monad.IO.Class
import Data.Text (Text)
fork ::
MonadIO m =>
Backend ->
Closure (Dict (Serializable a)) ->
Closure (IO a) ->
m (Handle a)
fork :: Backend
-> Closure (Dict (Serializable a))
-> Closure (IO a)
-> m (Handle a)
fork Backend
b Closure (Dict (Serializable a))
d Closure (IO a)
c = IO (Handle a) -> m (Handle a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Handle a) -> m (Handle a)) -> IO (Handle a) -> m (Handle a)
forall a b. (a -> b) -> a -> b
$ Closure (Dict (Serializable a))
-> Closure (IO a) -> Backend -> IO (Handle a)
forall i.
Closure (Dict (Serializable i))
-> Closure (IO i) -> Backend -> IO (Handle i)
runBackend Closure (Dict (Serializable a))
d Closure (IO a)
c Backend
b
await :: (MonadIO m, MonadThrow m) => Handle a -> m a
await :: Handle a -> m a
await = IO (Either Text a) -> m (Either Text a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either Text a) -> m (Either Text a))
-> (Handle a -> IO (Either Text a))
-> Handle a
-> m (Either Text a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle a -> IO (Either Text a)
forall a. Handle a -> IO (Either Text a)
tryAwait (Handle a -> m (Either Text a))
-> (Either Text a -> m a) -> Handle a -> m a
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (Text -> m a) -> (a -> m a) -> Either Text a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ExecutorFailedException -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (ExecutorFailedException -> m a)
-> (Text -> ExecutorFailedException) -> Text -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ExecutorFailedException
ExecutorFailedException) a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
newtype ExecutorFailedException = ExecutorFailedException Text
deriving (Int -> ExecutorFailedException -> ShowS
[ExecutorFailedException] -> ShowS
ExecutorFailedException -> String
(Int -> ExecutorFailedException -> ShowS)
-> (ExecutorFailedException -> String)
-> ([ExecutorFailedException] -> ShowS)
-> Show ExecutorFailedException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExecutorFailedException] -> ShowS
$cshowList :: [ExecutorFailedException] -> ShowS
show :: ExecutorFailedException -> String
$cshow :: ExecutorFailedException -> String
showsPrec :: Int -> ExecutorFailedException -> ShowS
$cshowsPrec :: Int -> ExecutorFailedException -> ShowS
Show, ExecutorFailedException -> ExecutorFailedException -> Bool
(ExecutorFailedException -> ExecutorFailedException -> Bool)
-> (ExecutorFailedException -> ExecutorFailedException -> Bool)
-> Eq ExecutorFailedException
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExecutorFailedException -> ExecutorFailedException -> Bool
$c/= :: ExecutorFailedException -> ExecutorFailedException -> Bool
== :: ExecutorFailedException -> ExecutorFailedException -> Bool
$c== :: ExecutorFailedException -> ExecutorFailedException -> Bool
Eq)
instance Exception ExecutorFailedException