Module

Resource

Implementation of the bracket/handler/resource pattern

This module provides a safe interface to the pattern. None of the values in here should make it possible to easily leak resources (though anything is possible if you try hard enough). The intent isn't to protect you from yourself, rather to make it easy to do the right thing.

#Resource

type Resource = Resource

The abstraction over safe resource management.

Any values embeded in this data type will be safely acquired before use, and released after they're done being used. Will also release the resources in the face of exceptions.

#new

new :: forall a. Aff a -> (a -> Aff Unit) -> Resource a

A fairly safe way to construct a Resource _.

This function can be easier to use sometimes than the continuation-based approach.

Relies on the underlying Aff _ behavior of bracketing for safety.

#run

run :: Resource Unit -> Aff Unit

Runs the Resource _.

This cannot leak the resource as it's not known what the resource is.

#with

with :: forall a. Resource a -> (a -> Aff Unit) -> Aff Unit

Runs the Resource _ while passing the acquired resource to a callback.

This cannot leak the resource as the callback cannot return the resource.

Modules