-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | 🍱 Manage stateful components.
--   
--   Bento manages stateful components.
@package bento
@version 0.1.0


-- | Bento manages stateful components. It is inspired by <a>Stuart
--   Sierra's Component</a> library for Clojure.
module Bento

-- | A stateful component. Usually you will define an instance of this
--   class to a data type that contains all of its runtime state.
--   
--   <pre>
--   data Example = Example { handle :: <a>Handle</a> }
--   instance <a>Component</a> Example where
--       -- To be defined...
--   </pre>
class Component component where {
    
    -- | Everything necessary to start the component. Typically this is a
    --   tuple, but you are free to use whichever data structure you want. If
    --   your component does not have any dependencies, use <tt>()</tt>, the
    --   empty tuple.
    --   
    --   <pre>
    --   type <a>Dependencies</a> Example = (<a>FilePath</a>, <a>IOMode</a>)
    --   </pre>
    type family Dependencies component :: *;
}

-- | Starts the component. This is where you should do things like open
--   file handles, set up connections, and generally acquire resources. If
--   anything goes wrong, just throw an exception, preferrably with
--   <a>throwIO</a>.
--   
--   This function should not block forever. If you need to start something
--   that should keep running, like a server, put it on another thread with
--   <a>forkIO</a>.
--   
--   <pre>
--   <a>start</a> (path, mode) = do
--       h &lt;- <a>openFile</a> path mode
--       let component = Example { handle = h }
--       <a>return</a> component
--   </pre>
start :: Component component => Dependencies component -> IO component

-- | Stops the component. Generally this will do the opposite of whatever
--   you did in <a>start</a>. The default implementation does nothing,
--   which can be enough if you want the garbage collector to handle
--   everything.
--   
--   <pre>
--   <a>stop</a> component = do
--       <a>hClose</a> (handle component)
--   </pre>
stop :: Component component => component -> IO ()
