resource-effectful-0.1.0.0: A region-based resource effect for the effectful ecosystem.
Copyright(c) Michael Szvetits 2023
LicenseBSD-3-Clause (see the file LICENSE)
Maintainertypedbyte@qualified.name
Stabilitystable
Portabilityportable
Safe HaskellSafe-Inferred
LanguageGHC2021

Effectful.Resource

Description

A region-based resource effect for the effectful ecosystem.

Synopsis

Resource Effect

data Resource :: Effect Source #

The region-based resource effect.

Instances

Instances details
type DispatchOf Resource Source # 
Instance details

Defined in Effectful.Resource

newtype StaticRep Resource Source # 
Instance details

Defined in Effectful.Resource

runResource :: IOE :> es => Eff (Resource ': es) a -> Eff es a Source #

Runs the resource effect.

Manage Regions

data Region Source #

A region owns resources and frees them on close.

Instances

Instances details
Eq Region Source # 
Instance details

Defined in Effectful.Resource

Methods

(==) :: Region -> Region -> Bool #

(/=) :: Region -> Region -> Bool #

withRegion :: Resource :> es => Eff es a -> Eff es a Source #

Runs a computation in a new region.

currentRegion :: Resource :> es => Eff es Region Source #

Gets the current region.

Manage Resources

data Key Source #

Each resource is identified by a unique key.

Instances

Instances details
Eq Key Source # 
Instance details

Defined in Effectful.Resource

Methods

(==) :: Key -> Key -> Bool #

(/=) :: Key -> Key -> Bool #

data InvalidKey Source #

An error which occurs if a key is freed/moved that has already been freed/moved.

Constructors

InvalidKey 

manage Source #

Arguments

:: Resource :> es 
=> IO a

The computation which acquires the resource.

-> (a -> IO b)

The computation which releases the resource.

-> Eff es a

The acquired resource.

Allocates a resource in the current region which is automatically freed at the end of the region.

allocate Source #

Arguments

:: Resource :> es 
=> IO a

The computation which acquires the resource.

-> (a -> IO b)

The computation which releases the resource.

-> Eff es (a, Key)

The acquired resource and its corresponding key.

Allocates a resource in the current region which can be moved and freed manually using its key.

free :: Key -> Eff es () Source #

Frees a resource manually.

freeAll :: Foldable t => t Key -> Eff es () Source #

Frees a collection of resources manually.

move :: Resource :> es => Key -> Region -> Eff es Key Source #

Moves a resource to the specified region, yielding a new key for the resource. The old key is invalid after the movement.

move_ :: Resource :> es => Key -> Region -> Eff es () Source #

Moves a resource to the specified region. It is freed at the end of this region. The key of the moved resource is invalid after the movement.

defer :: Resource :> es => IO a -> Eff es () Source #

Associats a cleanup action with the current region which is executed when the region is closed.