module Control.Concurrent.ForkableT
(
ForkableT(..)
, Forkable(..)
)
where
import Control.Concurrent
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Error
import Control.Monad.Writer
import Control.Monad.Trans.Control
class ForkableT t where
forkT :: (Forkable m n) => t n () -> t m ThreadId
default forkT :: (MonadTransControl t, Forkable m n) => t n () -> t m ThreadId
forkT t = liftWith $ \run -> fork $ run t >> return ()
class (MonadIO m, MonadIO n) => Forkable m n where
fork :: n () -> m ThreadId
default fork :: ForkableT t => t n () -> t m ThreadId
fork = forkT
instance Forkable IO IO where
fork = forkIO
instance ForkableT (ReaderT r)
instance ForkableT (StateT s)
instance (Monoid w) => ForkableT (WriterT w)
instance (Error e) => ForkableT (ErrorT e)
instance (Forkable m n) => Forkable (ReaderT r m) (ReaderT r n)
instance (Forkable m n) => Forkable (StateT s m) (StateT s n)
instance (Forkable m n, Error e) => Forkable (ErrorT e m) (ErrorT e n)
instance (Forkable m n) => Forkable (StateT s m) (ReaderT s n) where
fork r = lift . runReaderT (fork r) =<< get
instance (Forkable m n) => Forkable (ReaderT s m) (StateT s n) where
fork r = lift . evalStateT (fork r) =<< ask