-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Monad for allocation and cleanup of application resources
--
-- This library allows you to allocate resources with clean up strategies
-- when initializing your application. It then provides a Monadic
-- interface to compose multiple resources without having to deal with
-- cleanup operations explicitely.
@package componentm
@version 0.0.0.2
module Control.Monad.Component.Internal.Types
-- | Exception thrown by the runComponentM family of functions
data ComponentError
-- | Failure raised when the Application Callback given to a
-- runComponentM function throws an exception
ComponentRuntimeFailed :: !SomeException -> !TeardownResult -> ComponentError
-- | Exception that was originally thrown by the Application Callback
[componentErrorOriginalException] :: ComponentError -> !SomeException
-- | Result from the execution allocated resources teardown
[componentErrorTeardownResult] :: ComponentError -> !TeardownResult
-- | Failure raised when execution of ComponentM throws an exception
ComponentBuildFailed :: ![ComponentBuildError] -> !TeardownResult -> ComponentError
-- | Exceptions thrown by IO sub-routines used when constructing
-- ComponentM values (e.g. buildComponent)
[componentErrorBuildErrors] :: ComponentError -> ![ComponentBuildError]
-- | Result from the execution allocated resources teardown
[componentErrorTeardownResult] :: ComponentError -> !TeardownResult
-- | Exception raised on the execution of IO sub-routines used when
-- constructing ComponentM values (e.g. buildComponent)
data ComponentBuildError
-- | Failure thrown when using the same component key on a Component
-- composition
DuplicatedComponentKeyDetected :: !Description -> ComponentBuildError
-- | Failure thrown when the allocation sub-routine of a Component fails
-- with an exception
ComponentAllocationFailed :: !Description -> !SomeException -> ComponentBuildError
-- | Failure thrown when calling the throwM when composing
-- ComponentM values
ComponentErrorThrown :: !SomeException -> ComponentBuildError
-- | Failure thrown when calling liftIO fails with an exception
ComponentIOLiftFailed :: !SomeException -> ComponentBuildError
-- | Represents the construction of a Component in your application,
-- components may be composed using a Monad or Applicative
-- interface.
newtype ComponentM a
ComponentM :: (IO (Either ([ComponentBuildError], BuildTable) (a, BuildTable))) -> ComponentM a
-- | Contains metadata about the build of a resource from a
-- ComponentM value
data Build
Build :: !Description -> !Teardown -> !NominalDiffTime -> !(Maybe SomeException) -> !(Set Description) -> Build
-- | Name of the component built
[componentDesc] :: Build -> !Description
-- | Cleanup sub-routine of the component built
[componentTeardown] :: Build -> !Teardown
-- | Elasped time in the allocation of a component resource
[buildElapsedTime] :: Build -> !NominalDiffTime
-- | Error thrown in the allocation of a component resource
[buildFailure] :: Build -> !(Maybe SomeException)
-- | What other components this build depends on
[buildDependencies] :: Build -> !(Set Description)
-- | Wraps a collection of Build records
newtype BuildResult
BuildResult :: [Build] -> BuildResult
[toBuildList] :: BuildResult -> [Build]
-- | Result from a Teardown sub-routine
data TeardownResult :: *
-- | An event record used to trace the execution of an application
-- initialization and teardown
data ComponentEvent
ComponentBuilt :: !BuildResult -> ComponentEvent
ComponentReleased :: !TeardownResult -> ComponentEvent
ComponentErrorDetected :: !ComponentError -> ComponentEvent
buildTableToOrderedList :: BuildTable -> [Build]
buildTableToTeardown :: Text -> BuildTable -> IO Teardown
instance GHC.Generics.Generic Control.Monad.Component.Internal.Types.Build
instance GHC.Show.Show Control.Monad.Component.Internal.Types.ComponentError
instance GHC.Generics.Generic Control.Monad.Component.Internal.Types.ComponentError
instance GHC.Show.Show Control.Monad.Component.Internal.Types.ComponentBuildError
instance GHC.Generics.Generic Control.Monad.Component.Internal.Types.ComponentBuildError
instance GHC.Base.Functor Control.Monad.Component.Internal.Types.ComponentM
instance GHC.Base.Applicative Control.Monad.Component.Internal.Types.ComponentM
instance GHC.Base.Monad Control.Monad.Component.Internal.Types.ComponentM
instance Control.Monad.Catch.MonadThrow Control.Monad.Component.Internal.Types.ComponentM
instance Control.Monad.IO.Class.MonadIO Control.Monad.Component.Internal.Types.ComponentM
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.ComponentEvent
instance RIO.Prelude.Display.Display Control.Monad.Component.Internal.Types.ComponentEvent
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.BuildResult
instance RIO.Prelude.Display.Display Control.Monad.Component.Internal.Types.BuildResult
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.Build
instance RIO.Prelude.Display.Display Control.Monad.Component.Internal.Types.Build
instance GHC.Exception.Exception Control.Monad.Component.Internal.Types.ComponentError
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.ComponentError
instance GHC.Exception.Exception Control.Monad.Component.Internal.Types.ComponentBuildError
instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.ComponentBuildError
module Control.Monad.Component.Internal.Core
-- | Use this function when you want to allocate a new resource (e.g.
-- Database, Socket, etc). It registers the constructed resource in your
-- application component tree and guarantees that its cleanup sub-routine
-- is executed at the end of your program.
--
-- This function is similar to the bracket function with the
-- caveat that it expects a Text argument which identifies the
-- component being allocated.
--
-- NOTE: The name of your component must be unique; otherwise a
-- DuplicatedComponentKeyDetected will be thrown
buildComponent :: Text -> IO a -> (a -> IO ()) -> ComponentM a
-- | Transforms an IO sub-routine into a ComponentM
-- sub-routine; the given IO sub-routine returns a resource that
-- does not allocate any other resources that would need to be cleaned up
-- on a system shutdown.
--
-- This is similar to using liftIO, with the caveat that the
-- library will register the given IO sub-routine as a Component,
-- and it will keep track and report its initialization timespan
buildComponent_ :: Text -> IO a -> ComponentM a
-- | Constructs the environment of your application by executing the
-- IO sub-routines provided in the buildComponent and
-- buildComponent_ functions; it then executes a callback where
-- your main application will run.
--
-- This function:
--
--
-- - Keeps track of initialization elapsed time for each component of
-- your application
-- - Initializes components concurrently as long as they are composed
-- using Applicative functions
-- - Builds a graph of your dependencies automatically when composing
-- your ComponentM values via Applicative or Monad
-- interfaces; it then guarantees the execution of cleanup operations in
-- a topological sorted order
-- - Guarantees the proper cleanup of previously allocated resources if
-- the creation of a resource throws an exception on initialization
-- - Guarantees best-effort cleanup of resources on application
-- teardown in the scenario where a cleanup sub-routine throws an
-- exception
-- - Keeps track of teardown elasped time for each component of your
-- application; and reports what exceptions was thrown in case of
-- failures
--
--
-- If you want to trace the behavior of your application on
-- initialization and teardown, use runComponentM1 instead
runComponentM :: Text -> ComponentM a -> (a -> IO b) -> IO b
-- | Enhances runComponentM with a callback function that emits
-- ComponentEvent records. These events are a great way of tracing
-- the lifecycle and structure of your application.
runComponentM1 :: (ComponentEvent -> IO ()) -> Text -> ComponentM a -> (a -> IO b) -> IO b
-- |
--
-- ComponentM values wraps vanilla IO sub-routines whose
-- responsibility is to allocate resources that your application may need
-- (e.g. database connections, tcp sockets, etc). Your program will
-- execute these ComponentM sub-routines at the beginning of it's
-- lifecyle, building an environment that your main application needs in
-- order to work as intended.
--
-- By using ComponentM sub-routines your program will
-- automatically:
--
--
-- - Compose the cleanup sub-routines of all your allocated
-- resources
-- - Keep track of initialization time for each resource needed in your
-- application
-- - Keep track of teardown time for each resources needed in your
-- application.
-- - Isolate the teardown of each resource in your application,
-- ensuring no thrown exception will affect the cleanup of
-- resources.
-- - Initialize resources concurrently when using Applicative
-- notation
-- - Build a dependency graph of your application resources when using
-- Applicative or Monad notation; and then guarantees
-- the execution of cleanup operations in a topological sorted order
-- - Make sure that previously allocated resources are cleaned up when
-- a resource throws an exception on initialization
-- - Report all exceptions thrown on each resource teardown
-- - Document (through types) what is the purpose of some of the
-- IO sub-routines in your program
--
--
-- These properties are crucial when applications need to run for long
-- periods of time and they are reloaded (without a process restart). It
-- also ensures that resources are cleaned tightly when doing REPL driven
-- development through GHCi.
module Control.Monad.Component
-- | Use this function when you want to allocate a new resource (e.g.
-- Database, Socket, etc). It registers the constructed resource in your
-- application component tree and guarantees that its cleanup sub-routine
-- is executed at the end of your program.
--
-- This function is similar to the bracket function with the
-- caveat that it expects a Text argument which identifies the
-- component being allocated.
--
-- NOTE: The name of your component must be unique; otherwise a
-- DuplicatedComponentKeyDetected will be thrown
buildComponent :: Text -> IO a -> (a -> IO ()) -> ComponentM a
-- | Transforms an IO sub-routine into a ComponentM
-- sub-routine; the given IO sub-routine returns a resource that
-- does not allocate any other resources that would need to be cleaned up
-- on a system shutdown.
--
-- This is similar to using liftIO, with the caveat that the
-- library will register the given IO sub-routine as a Component,
-- and it will keep track and report its initialization timespan
buildComponent_ :: Text -> IO a -> ComponentM a
-- | Represents the construction of a Component in your application,
-- components may be composed using a Monad or Applicative
-- interface.
data ComponentM a
-- | Constructs the environment of your application by executing the
-- IO sub-routines provided in the buildComponent and
-- buildComponent_ functions; it then executes a callback where
-- your main application will run.
--
-- This function:
--
--
-- - Keeps track of initialization elapsed time for each component of
-- your application
-- - Initializes components concurrently as long as they are composed
-- using Applicative functions
-- - Builds a graph of your dependencies automatically when composing
-- your ComponentM values via Applicative or Monad
-- interfaces; it then guarantees the execution of cleanup operations in
-- a topological sorted order
-- - Guarantees the proper cleanup of previously allocated resources if
-- the creation of a resource throws an exception on initialization
-- - Guarantees best-effort cleanup of resources on application
-- teardown in the scenario where a cleanup sub-routine throws an
-- exception
-- - Keeps track of teardown elasped time for each component of your
-- application; and reports what exceptions was thrown in case of
-- failures
--
--
-- If you want to trace the behavior of your application on
-- initialization and teardown, use runComponentM1 instead
runComponentM :: Text -> ComponentM a -> (a -> IO b) -> IO b
-- | Enhances runComponentM with a callback function that emits
-- ComponentEvent records. These events are a great way of tracing
-- the lifecycle and structure of your application.
runComponentM1 :: (ComponentEvent -> IO ()) -> Text -> ComponentM a -> (a -> IO b) -> IO b
-- | Exception thrown by the runComponentM family of functions
data ComponentError
-- | Failure raised when the Application Callback given to a
-- runComponentM function throws an exception
ComponentRuntimeFailed :: !SomeException -> !TeardownResult -> ComponentError
-- | Exception that was originally thrown by the Application Callback
[componentErrorOriginalException] :: ComponentError -> !SomeException
-- | Result from the execution allocated resources teardown
[componentErrorTeardownResult] :: ComponentError -> !TeardownResult
-- | Failure raised when execution of ComponentM throws an exception
ComponentBuildFailed :: ![ComponentBuildError] -> !TeardownResult -> ComponentError
-- | Exceptions thrown by IO sub-routines used when constructing
-- ComponentM values (e.g. buildComponent)
[componentErrorBuildErrors] :: ComponentError -> ![ComponentBuildError]
-- | Result from the execution allocated resources teardown
[componentErrorTeardownResult] :: ComponentError -> !TeardownResult
-- | Exception raised on the execution of IO sub-routines used when
-- constructing ComponentM values (e.g. buildComponent)
data ComponentBuildError
-- | Failure thrown when using the same component key on a Component
-- composition
DuplicatedComponentKeyDetected :: !Description -> ComponentBuildError
-- | Failure thrown when the allocation sub-routine of a Component fails
-- with an exception
ComponentAllocationFailed :: !Description -> !SomeException -> ComponentBuildError
-- | Failure thrown when calling the throwM when composing
-- ComponentM values
ComponentErrorThrown :: !SomeException -> ComponentBuildError
-- | Failure thrown when calling liftIO fails with an exception
ComponentIOLiftFailed :: !SomeException -> ComponentBuildError
-- | An event record used to trace the execution of an application
-- initialization and teardown
data ComponentEvent
ComponentBuilt :: !BuildResult -> ComponentEvent
ComponentReleased :: !TeardownResult -> ComponentEvent
ComponentErrorDetected :: !ComponentError -> ComponentEvent
-- | Contains metadata about the build of a resource from a
-- ComponentM value
data Build
-- | Elasped time in the allocation of a component resource
buildElapsedTime :: Build -> NominalDiffTime
-- | Error thrown in the allocation of a component resource
buildFailure :: Build -> (Maybe SomeException)
-- | Wraps a collection of Build records
data BuildResult
toBuildList :: BuildResult -> [Build]
-- | Result from a Teardown sub-routine
data TeardownResult :: *
-- | Result is composed by multiple teardown sub-routines
BranchResult :: !Description -> !NominalDiffTime -> !Bool -> ![TeardownResult] -> TeardownResult
-- | Text description of parent teardown spec
[resultDescription] :: TeardownResult -> !Description
-- | Sum of elapsed time on sub-routines execution
[resultElapsedTime] :: TeardownResult -> !NominalDiffTime
-- | Tells if any sub-routines failed
[resultDidFail] :: TeardownResult -> !Bool
-- | Results of inner sub-routines
[resultListing] :: TeardownResult -> ![TeardownResult]
-- | Result represents a single teardown sub-routine
LeafResult :: !Description -> !NominalDiffTime -> !Maybe SomeException -> TeardownResult
-- | Text description of parent teardown spec
[resultDescription] :: TeardownResult -> !Description
-- | Sum of elapsed time on sub-routines execution
[resultElapsedTime] :: TeardownResult -> !NominalDiffTime
-- | Exception from sub-routine
[resultError] :: TeardownResult -> !Maybe SomeException
-- | Represents a stub cleanup operation (for lifting pure values)
EmptyResult :: !Description -> TeardownResult
-- | Text description of parent teardown spec
[resultDescription] :: TeardownResult -> !Description
-- | Throw an exception. Note that this throws when this action is run in
-- the monad m, not when it is applied. It is a generalization
-- of Control.Exception's throwIO.
--
-- Should satisfy the law:
--
--
-- throwM e >> f = throwM e
--
throwM :: MonadThrow m => forall e a. Exception e => e -> m a