streamly-0.8.0: Dataflow programming and declarative concurrency
Copyright(c) 2020 Composewell Technologies and Contributors
LicenseBSD-3-Clause
Maintainerstreamly@composewell.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Streamly.Internal.Data.IOFinalizer

Description

A value associated with an IO action that is automatically called whenever the value is garbage collected.

Synopsis

Documentation

data IOFinalizer Source #

An IOFinalizer has an associated IO action that is automatically called whenever the finalizer is garbage collected. The action can be run and cleared prematurely.

You can hold a reference to the finalizer in your data structure, if the data structure gets garbage collected the finalizer will be called.

It is implemented using mkWeakIORef.

Pre-release

newIOFinalizer :: (MonadIO m, MonadBaseControl IO m) => m a -> m IOFinalizer Source #

Create a finalizer that calls the supplied function automatically when the it is garbage collected.

/The finalizer is always run using the state of the monad that is captured at the time of calling newFinalizer./

Note: To run it on garbage collection we have no option but to use the monad state captured at some earlier point of time. For the case when the finalizer is run manually before GC we could run it with the current state of the monad but we want to keep both the cases consistent.

Pre-release

runIOFinalizer :: MonadIO m => IOFinalizer -> m () Source #

Run the action associated with the finalizer and deactivate it so that it never runs again. Note, the finalizing action runs with async exceptions masked.

Pre-release

clearingIOFinalizer :: MonadBaseControl IO m => IOFinalizer -> m a -> m a Source #

Run an action clearing the finalizer atomically wrt async exceptions. The action is run with async exceptions masked.

Pre-release