IOR-0.1: Region based resource management for the IO monad.

Stabilityexperimental
Maintainertomac `at` pacific `dot` net `dot` au

System.IOR.Resource

Description

Resource management in the IOR monad.

Synopsis

Documentation

data Resource r a Source

Resource r a wraps a resource of type a so it can be managed inside region r and automatically released upon exit from r.

Instances

Typeable2 Resource 
Eq (Resource r a) 
(Data r, Data a) => Data (Resource r a) 

getResource :: Resource r a -> aSource

Extract a from the Resource wrapper.

manage :: a -> (a -> IO ()) -> IOR r rs (Resource r a)Source

manage a f will create a new Resource wrapper around the value of type a in region r, given a finalizer f. Each finalizer is guaranteed to automatically be called upon exit from the region. Finalizers are called in the last in, first out fashion. So the finalizer of the very last resource allocated will be the first to get called.

Note that finalizers must not throw any errors. Failing to ensure that all errors in a finalizer are handled may result in a resource leak.

release :: RElem r' rs => Resource r' a -> IOR r rs ()Source

release res is used to force the resource res to be released immediately. Finalizer for res will be called and removed from the stack of finalizers in region r'.