Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- newtype Stop = Stop InternalState
- runStop :: Stop -> IO ()
- newtype RioT m a = RioT {}
- type RIO = RioT IO
- runRIO :: RIO a -> Stop -> IO (a, Warmup)
- 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
- 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)
- 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)
- unsafeRun :: forall a ins out m. (Typeable a, Typeable m, MonadIO m, Contains (RioT m a) out) => Registry ins out -> m a
- unsafeRunWithStop :: forall a ins out m. (Typeable a, Typeable m, MonadIO m, Contains (RioT m a) out) => Registry ins out -> m (a, Stop)
- warmupWith :: Applicative m => Warmup -> RioT m ()
- allocate :: MonadResource m => IO a -> (a -> IO ()) -> RioT m a
Documentation
This newtype creates a monad to sequence component creation actions, cumulating start/stop tasks found along the way
Instances
MonadTrans RioT Source # | |
Defined in Data.Registry.RIO | |
(MonadBase IO m, MonadIO m) => MonadBase IO (RioT m) Source # | |
Defined in Data.Registry.RIO | |
Monad m => Monad (RioT m) Source # | |
Functor m => Functor (RioT m) Source # | |
Monad m => Applicative (RioT m) Source # | |
MonadIO m => MonadIO (RioT m) Source # | |
Defined in Data.Registry.RIO | |
MonadThrow m => MonadThrow (RioT m) Source # | |
Defined in Data.Registry.RIO | |
MonadResource m => MonadResource (RioT m) Source # | |
Defined in Data.Registry.RIO liftResourceT :: ResourceT IO a -> RioT m a # |
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 #
warmupWith :: Applicative m => Warmup -> RioT m () Source #
Lift a Warmup
action into the 'RioT m' monad