| Copyright | (c) Roman Gonzalez 20172018 |
|---|---|
| License | MIT |
| Maintainer | open-source@roman-gonzalez.info |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
Control.Teardown
Contents
Description
Provides functions that help on the creation of Application teardown sub-routines
Synopsis
- class HasTeardown teardown where
- class IResource resource
- data Teardown
- data TeardownResult
- = BranchResult {
- resultDescription :: !Description
- resultElapsedTime :: !NominalDiffTime
- resultDidFail :: !Bool
- resultListing :: ![TeardownResult]
- | LeafResult {
- resultDescription :: !Description
- resultElapsedTime :: !NominalDiffTime
- resultError :: !(Maybe SomeException)
- | EmptyResult {
- resultDescription :: !Description
- = BranchResult {
- runTeardown :: HasTeardown t => t -> IO TeardownResult
- runTeardown_ :: HasTeardown t => t -> IO ()
- emptyTeardown :: Description -> Teardown
- newTeardown :: IResource resource => Text -> resource -> IO Teardown
- didTeardownFail :: TeardownResult -> Bool
- failedToredownCount :: TeardownResult -> Int
- toredownCount :: TeardownResult -> Int
- prettyTeardownResult :: TeardownResult -> Doc ann
Typeclasses for extending teardown functionality
class HasTeardown teardown where #
A record that is or contains a Teardown sub-routine should
instantiate this typeclass
Minimal complete definition
Methods
getTeardown :: teardown -> Teardown #
Executes teardown sub-routine returning a TeardownResult
Instances
| HasTeardown Teardown # | |
Defined in Control.Teardown.Internal.Core Methods getTeardown :: Teardown -> Teardown # | |
A resource or sub-routine that can be transformed into a Teardown
operation
Minimal complete definition
Instances
| IResource Teardown # | Wraps an existing Teardown record; the wrapper Teardown record represents a "parent resource" on the TeardownResult |
Defined in Control.Teardown.Internal.Core | |
| (TypeError (Text "DEPRECATED: Execute a 'newTeardown' call per allocated resource") :: Constraint) => IResource [(Text, IO ())] # | Deprecated instance that creates a Teardown record from a list of cleanup sub-routines (creating a Teardown record for each). WARNING: This function assumes you are creating many sub-resources at once; this approach has a major risk of leaking resources, and that is why is deprecated; execute newTeardown for every resource you allocate. NOTE: The Since 0.4.1.0 |
Defined in Control.Teardown.Internal.Core | |
| IResource [Teardown] # | Wraps a list of Teardown record; the new record will have one extra level
of description. Same behaviour as the |
Defined in Control.Teardown.Internal.Core | |
| IResource (IO [Teardown]) # | Wraps an IO action that returns a list of Teardown record; the new record
will have one extra level of description. Same behaviour as the |
Defined in Control.Teardown.Internal.Core | |
| IResource (IO [TeardownResult]) # | Creates a Teardown record from executing a sub-routine that releases
short-lived Teardown records. This is useful when short-lived Teardown
are accumulated on a collection inside a mutable variable (e.g. |
Defined in Control.Teardown.Internal.Core Methods newTeardown :: Text -> IO [TeardownResult] -> IO Teardown # | |
| IResource (IO ()) # | Creates a new Teardown record from a cleanup "IO ()" sub-routine; the Teardown API guarantees:
IMPORTANT: The |
Defined in Control.Teardown.Internal.Core | |
Cleanup main type and function
Sub-routine that performs a resource cleanup operation
Instances
| Generic Teardown # | |
| NFData Teardown # | |
Defined in Control.Teardown.Internal.Types | |
| IResource Teardown # | Wraps an existing Teardown record; the wrapper Teardown record represents a "parent resource" on the TeardownResult |
Defined in Control.Teardown.Internal.Core | |
| HasTeardown Teardown # | |
Defined in Control.Teardown.Internal.Core Methods getTeardown :: Teardown -> Teardown # | |
| IResource [Teardown] # | Wraps a list of Teardown record; the new record will have one extra level
of description. Same behaviour as the |
Defined in Control.Teardown.Internal.Core | |
| IResource (IO [Teardown]) # | Wraps an IO action that returns a list of Teardown record; the new record
will have one extra level of description. Same behaviour as the |
Defined in Control.Teardown.Internal.Core | |
| type Rep Teardown # | |
Defined in Control.Teardown.Internal.Types type Rep Teardown = D1 (MetaData "Teardown" "Control.Teardown.Internal.Types" "teardown-0.5.0.0-BQUradBa2TfIWcyButdekP" True) (C1 (MetaCons "Teardown" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (IO TeardownResult)))) | |
data TeardownResult #
Result from a Teardown sub-routine
Constructors
| BranchResult | Result is composed by multiple teardown sub-routines |
Fields
| |
| LeafResult | Result represents a single teardown sub-routine |
Fields
| |
| EmptyResult | Represents a stub cleanup operation (for lifting pure values) |
Fields
| |
Instances
runTeardown :: HasTeardown t => t -> IO TeardownResult #
Executes all composed Teardown sub-routines safely. This version returns a Tree data structure wich can be used to gather facts from the resource cleanup
runTeardown_ :: HasTeardown t => t -> IO () #
Executes all composed Teardown sub-routines safely
Functions to create a Teardown record
emptyTeardown :: Description -> Teardown #
Creates a stub Teardown sub-routine, normally used when a contract expects a teardown return but there is no allocation being made
Functions to deal with results from teardown call
didTeardownFail :: TeardownResult -> Bool #
Returns a boolean indicating if any of the cleanup sub-routine failed
failedToredownCount :: TeardownResult -> Int #
Returns number of sub-routines that threw an exception on execution of "runTeardown"
toredownCount :: TeardownResult -> Int #
Returns number of released resources from a "runTeardown" execution
prettyTeardownResult :: TeardownResult -> Doc ann #
Renders an ASCII Tree with the TeardownResult of a Teardown sub-routine execution