Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> |
---|
Control.Monad.Trans.Region.OnExit
Description
This module is not intended for end-users. It should only be used by library
authors wishing to extend this regions
library.
- type Finalizer = IO ()
- data FinalizerHandle r
- onExit :: MonadIO pr => Finalizer -> RegionT s pr (FinalizerHandle (RegionT s pr))
Documentation
An IO
computation that closes or finalizes a resource. For example
"hClose someHandle
" or "free somePtr
".
data FinalizerHandle r Source
A handle to a Finalizer
that allows you to duplicate it to a parent region
using dup
.
Duplicating a finalizer means that instead of it being performed when the current region terminates it is performed when the parent region terminates.
Instances
onExit :: MonadIO pr => Finalizer -> RegionT s pr (FinalizerHandle (RegionT s pr))Source
Register the Finalizer
in the region. When the region terminates all
registered finalizers will be perfomed if they're not duplicated to a parent
region.
Note that finalizers are run in LIFO order (Last In First Out). So executing the following:
runRegionT $ do _ <- onExit $ putStrLn "finalizer 1" _ <- onExit $ putStrLn "finalizer 2" return ()
yields:
finalizer 2 finalizer 1