registry-0.1.0.2: 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 "modules as records of functions" where each module can allocate resources and have a "warmup phase" to preload data or asses 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 RIO a Source #

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

Constructors

RIO 

Fields

Instances
Monad RIO Source # 
Instance details

Defined in Data.Registry.RIO

Methods

(>>=) :: RIO a -> (a -> RIO b) -> RIO b #

(>>) :: RIO a -> RIO b -> RIO b #

return :: a -> RIO a #

fail :: String -> RIO a #

Functor RIO Source # 
Instance details

Defined in Data.Registry.RIO

Methods

fmap :: (a -> b) -> RIO a -> RIO b #

(<$) :: a -> RIO b -> RIO a #

Applicative RIO Source # 
Instance details

Defined in Data.Registry.RIO

Methods

pure :: a -> RIO a #

(<*>) :: RIO (a -> b) -> RIO a -> RIO b #

liftA2 :: (a -> b -> c) -> RIO a -> RIO b -> RIO c #

(*>) :: RIO a -> RIO b -> RIO b #

(<*) :: RIO a -> RIO b -> RIO a #

MonadIO RIO Source # 
Instance details

Defined in Data.Registry.RIO

Methods

liftIO :: IO a -> RIO a #

MonadThrow RIO Source # 
Instance details

Defined in Data.Registry.RIO

Methods

throwM :: Exception e => e -> RIO a #

MonadResource RIO Source # 
Instance details

Defined in Data.Registry.RIO

Methods

liftResourceT :: ResourceT IO a -> RIO a #

MonadBase IO RIO Source # 
Instance details

Defined in Data.Registry.RIO

Methods

liftBase :: IO α -> RIO α #

For production

withRegistry :: forall a b ins out. (Typeable a, Contains (RIO a) out, Solvable ins out) => Registry ins out -> (Result -> a -> IO b) -> IO b Source #

This function must be used to run services involving a top module It creates the top module 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. (Typeable a, Contains (RIO a) out, Solvable ins out) => Registry ins out -> ResourceT IO (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. (Typeable a, Contains (RIO a) out, Solvable ins out) => Registry ins out -> IO (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. (Typeable a, Contains (RIO a) out) => Registry ins out -> IO 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. (Typeable a, Contains (RIO a) out) => Registry ins out -> IO (a, Stop) Source #

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

Module creation

warmupWith :: Warmup -> RIO () Source #

Lift a Warmup action into the RIO monad

allocate :: IO a -> (a -> IO ()) -> RIO a Source #

Allocate some resource