{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveFunctor #-}
module Control.Distributed.Process.Async.Internal.Types
(
Async(..)
, AsyncRef
, AsyncTask(..)
, AsyncResult(..)
, CancelWait(..)
) where
import Control.Concurrent.STM
import Control.Distributed.Process
import Control.Distributed.Process.Serializable
( Serializable
, SerializableDict
)
import Data.Binary
import Data.Typeable (Typeable)
import Data.Monoid
import GHC.Generics
type AsyncRef = ProcessId
data Async a = Async {
_asyncWorker :: AsyncRef
, _asyncMonitor :: AsyncRef
, _asyncWait :: STM (AsyncResult a)
} deriving (Functor)
instance Eq (Async a) where
Async a b _ == Async c d _ = a == c && b == d
instance Ord (Async a) where
compare (Async a b _) (Async c d _) = a `compare` c <> b `compare` d
data AsyncTask a =
AsyncTask {
asyncTask :: Process a
}
| AsyncRemoteTask {
asyncTaskDict :: Static (SerializableDict a)
, asyncTaskNode :: NodeId
, asyncTaskProc :: Closure (Process a)
}
data AsyncResult a =
AsyncDone a
| AsyncFailed DiedReason
| AsyncLinkFailed DiedReason
| AsyncCancelled
| AsyncPending
deriving (Typeable, Generic, Functor)
instance Serializable a => Binary (AsyncResult a) where
deriving instance Eq a => Eq (AsyncResult a)
deriving instance Show a => Show (AsyncResult a)
data CancelWait = CancelWait
deriving (Typeable, Generic)
instance Binary CancelWait