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 RIO a = RIO {}
- withRIO :: MonadIO m => RIO a -> (a -> IO ()) -> m Result
- withRegistry :: forall a b ins out m. (Typeable a, Contains (RIO a) out, Solvable ins out, MonadIO m, MemoizedActions out) => Registry ins out -> (Result -> a -> IO b) -> m b
- runRegistryT :: forall a ins out m. (Typeable a, Contains (RIO a) out, Solvable ins out, MonadIO m, MemoizedActions out) => Registry ins out -> ResourceT m (a, Warmup)
- unsafeRunRIO :: (Typeable a, MonadIO m) => RIO a -> m a
- withNoWarmupRIO :: MonadIO m => RIO a -> (a -> IO b) -> m b
- withRIOIgnoreWarmupResult :: MonadIO m => RIO a -> (a -> IO b) -> m b
- withRIOAndWarmupResult :: MonadIO m => (Result -> IO ()) -> RIO a -> (a -> IO b) -> m b
- executeRegistry :: forall a ins out m. (Typeable a, Contains (RIO a) out, Solvable ins out, MonadIO m) => Registry ins out -> m (a, Warmup, Stop)
- unsafeRun :: forall a ins out m. (Typeable a, Contains (RIO a) out, MonadIO m) => Registry ins out -> m a
- unsafeRunDynamic :: forall a ins out m. (Typeable a, MonadIO m) => Registry ins out -> m a
- unsafeRunWithStop :: forall a ins out m. (Typeable a, Contains (RIO a) out, MonadIO m) => Registry ins out -> m (a, Stop)
- unsafeRunDynamicWithStop :: forall a ins out m. (Typeable a, MonadIO m) => Registry ins out -> m (a, Stop)
- warmupWith :: Warmup -> RIO ()
- allocate :: IO a -> (a -> IO ()) -> RIO a
Documentation
This newtype creates a monad to sequence component creation actions, cumulating start/stop tasks found along the way
Instances
Monad RIO Source # | |
Functor RIO Source # | |
Applicative RIO Source # | |
MonadIO RIO Source # | |
Defined in Data.Registry.RIO | |
Alternative RIO Source # | |
MonadThrow RIO Source # | |
Defined in Data.Registry.RIO | |
MonadResource RIO Source # | |
Defined in Data.Registry.RIO liftResourceT :: ResourceT IO a -> RIO a # | |
Alt RIO Source # | |
MonadBase IO RIO Source # | |
Defined in Data.Registry.RIO |
For production
withRIO :: MonadIO m => RIO a -> (a -> IO ()) -> m Result Source #
Use a RIO value and make sure that resources are closed Only run the action if the warmup is successful
withRegistry :: forall a b ins out m. (Typeable a, Contains (RIO a) out, Solvable ins out, MonadIO m, MemoizedActions out) => Registry ins out -> (Result -> a -> IO 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
We also make sure that all effects are memoized by calling memoizeAll
on the Registry here!
runRegistryT :: forall a ins out m. (Typeable a, Contains (RIO a) out, Solvable ins out, MonadIO m, MemoizedActions 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
unsafeRunRIO :: (Typeable a, MonadIO m) => RIO a -> m a Source #
This runs a RIO value without closing down resources or executing startup actions
withNoWarmupRIO :: MonadIO m => RIO a -> (a -> IO b) -> m b Source #
Use a RIO value and make sure that resources are closed Don't run the warmup
withRIOIgnoreWarmupResult :: MonadIO m => RIO a -> (a -> IO b) -> m b Source #
Use a RIO value and make sure that resources are closed Run the warmup but ignore the result
withRIOAndWarmupResult :: MonadIO m => (Result -> IO ()) -> RIO a -> (a -> IO b) -> m b Source #
Use a RIO value and make sure that resources are closed Run a unit function with the warmup result (print or throw exception)
executeRegistry :: forall a ins out m. (Typeable a, Contains (RIO a) out, Solvable ins out, MonadIO m) => 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, Contains (RIO a) out, MonadIO m) => 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
unsafeRunDynamic :: forall a ins out m. (Typeable a, MonadIO m) => 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 Don't even check that a component can be built out of the registry
unsafeRunWithStop :: forall a ins out m. (Typeable a, Contains (RIO a) out, MonadIO m) => Registry ins out -> m (a, Stop) Source #