registry-0.1.2.0: data structure for assembling components

Safe HaskellNone
LanguageHaskell2010

Data.Registry.RIO

Contents

Description

RIO is equivalent to ResourceT (WriterT Warmup IO) It can be used to instantiate "components as records of functions" where each component can allocate resources and have a "warmup phase" to preload data or assess if it is working properly.

Synopsis

Documentation

newtype Stop Source #

Data type encapsulating resource finalizers

Constructors

Stop InternalState 

runStop :: Stop -> IO () Source #

Run all finalizers

newtype RioT m a Source #

This newtype creates a monad to sequence component creation actions, cumulating start/stop tasks found along the way

Constructors

RioT 

Fields

Instances
MonadTrans RioT Source # 
Instance details

Defined in Data.Registry.RIO

Methods

lift :: Monad m => m a -> RioT m a #

(MonadBase IO m, MonadIO m) => MonadBase IO (RioT m) Source # 
Instance details

Defined in Data.Registry.RIO

Methods

liftBase :: IO α -> RioT m α #

Monad m => Monad (RioT m) Source # 
Instance details

Defined in Data.Registry.RIO

Methods

(>>=) :: RioT m a -> (a -> RioT m b) -> RioT m b #

(>>) :: RioT m a -> RioT m b -> RioT m b #

return :: a -> RioT m a #

fail :: String -> RioT m a #

Functor m => Functor (RioT m) Source # 
Instance details

Defined in Data.Registry.RIO

Methods

fmap :: (a -> b) -> RioT m a -> RioT m b #

(<$) :: a -> RioT m b -> RioT m a #

Monad m => Applicative (RioT m) Source # 
Instance details

Defined in Data.Registry.RIO

Methods

pure :: a -> RioT m a #

(<*>) :: RioT m (a -> b) -> RioT m a -> RioT m b #

liftA2 :: (a -> b -> c) -> RioT m a -> RioT m b -> RioT m c #

(*>) :: RioT m a -> RioT m b -> RioT m b #

(<*) :: RioT m a -> RioT m b -> RioT m a #

MonadIO m => MonadIO (RioT m) Source # 
Instance details

Defined in Data.Registry.RIO

Methods

liftIO :: IO a -> RioT m a #

MonadThrow m => MonadThrow (RioT m) Source # 
Instance details

Defined in Data.Registry.RIO

Methods

throwM :: Exception e => e -> RioT m a #

MonadResource m => MonadResource (RioT m) Source # 
Instance details

Defined in Data.Registry.RIO

Methods

liftResourceT :: ResourceT IO a -> RioT m a #

type RIO = RioT IO Source #

Specialization of RioT to IO

runRIO :: RIO a -> Stop -> IO (a, Warmup) Source #

For production

withRegistry :: forall a b ins out m. (Typeable a, Typeable m, MonadIO m, MonadUnliftIO m, Contains (RioT m a) out, Solvable ins out) => Registry ins out -> (Result -> a -> m b) -> m b Source #

This function must be used to run services involving a top component It creates the top component and invokes all warmup functions

The passed function f is used to decide whether to continue or not depending on the Result

runRegistryT :: forall a ins out m. (Typeable a, Typeable m, MonadIO m, Contains (RioT m a) out, Solvable ins out) => Registry ins out -> ResourceT m (a, Warmup) Source #

This can be used if you want to insert the component creation inside another action managed with ResourceT. Or if you want to call runResourceT yourself later

For testing

executeRegistry :: forall a ins out m. (Typeable a, Typeable m, MonadIO m, Contains (RioT m a) out, Solvable ins out) => Registry ins out -> m (a, Warmup, Stop) Source #

Instantiate the component but don't execute the warmup (it may take time) and keep the Stop value to clean resources later This function statically checks that the component can be instantiated

unsafeRun :: forall a ins out m. (Typeable a, Typeable m, MonadIO m, Contains (RioT m a) out) => Registry ins out -> m a Source #

Instantiate the component but don't execute the warmup (it may take time) and lose a way to cleanu up resources | Almost no compilation time is spent on checking that component resolution is possible

unsafeRunWithStop :: forall a ins out m. (Typeable a, Typeable m, MonadIO m, Contains (RioT m a) out) => Registry ins out -> m (a, Stop) Source #

Same as unsafeRun but keep the Stop value to be able to clean resources later

warmupWith :: Applicative m => Warmup -> RioT m () Source #

Lift a Warmup action into the 'RioT m' monad

allocate :: MonadResource m => IO a -> (a -> IO ()) -> RioT m a Source #

Allocate some resource