-- 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. -- -- Check Control.Monad.Component.Tutorial for an example and more -- information. @package componentm @version 0.0.0.1 -- |

Why use ComponentM?

-- -- 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: -- -- -- -- 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: -- -- -- -- 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 -- | 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