| Safe Haskell | Safe-Inferred | 
|---|---|
| Language | Haskell2010 | 
UnliftIO.Resource
Contents
Description
Unlifted Control.Monad.Trans.Resource.
Since: 1.1.10
Synopsis
- runResourceT :: MonadUnliftIO m => ResourceT m a -> m a
- liftResourceT :: MonadIO m => ResourceT IO a -> ResourceT m a
- allocateU :: (MonadUnliftIO m, MonadResource m) => m a -> (a -> m ()) -> m (ReleaseKey, a)
- data ResourceT m a
- data ReleaseKey
- class MonadIO m => MonadResource m
- release :: MonadIO m => ReleaseKey -> m ()
- allocate :: MonadResource m => IO a -> (a -> IO ()) -> m (ReleaseKey, a)
- register :: MonadResource m => IO () -> m ReleaseKey
- unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ()))
UnliftIO variants
runResourceT :: MonadUnliftIO m => ResourceT m a -> m a Source #
Unlifted version of runResourceT.
Since: 1.1.10
liftResourceT :: MonadIO m => ResourceT IO a -> ResourceT m a Source #
Lifted version of liftResourceT.
Since: 1.1.10
allocateU :: (MonadUnliftIO m, MonadResource m) => m a -> (a -> m ()) -> m (ReleaseKey, a) Source #
Unlifted allocate.
Since: 1.2.6
Reexports
The Resource transformer. This transformer keeps track of all registered
 actions, and calls them upon exit (via runResourceT). Actions may be
 registered via register, or resources may be allocated atomically via
 allocate. allocate corresponds closely to bracket.
Releasing may be performed before exit via the release function. This is a
 highly recommended optimization, as it will ensure that scarce resources are
 freed early. Note that calling release will deregister the action, so that
 a release action will only ever be called once.
Since 0.3.0
Instances
data ReleaseKey Source #
A lookup key for a specific release action. This value is returned by
 register and allocate, and is passed to release.
Since 0.3.0
class MonadIO m => MonadResource m Source #
A Monad which allows for safe resource allocation. In theory, any monad
 transformer stack which includes a ResourceT can be an instance of
 MonadResource.
Note: runResourceT has a requirement for a MonadUnliftIO m monad,
 which allows control operations to be lifted. A MonadResource does not
 have this requirement. This means that transformers such as ContT can be
 an instance of MonadResource. However, the ContT wrapper will need to be
 unwrapped before calling runResourceT.
Since 0.3.0
Minimal complete definition
Instances
release :: MonadIO m => ReleaseKey -> m () Source #
Call a release action early, and deregister it from the list of cleanup actions to be performed.
Since 0.3.0
Arguments
| :: MonadResource m | |
| => IO a | allocate | 
| -> (a -> IO ()) | free resource | 
| -> m (ReleaseKey, a) | 
Perform some allocation, and automatically register a cleanup action.
This is almost identical to calling the allocation and then
 registering the release action, but this properly handles masking of
 asynchronous exceptions.
Since 0.3.0
register :: MonadResource m => IO () -> m ReleaseKey Source #
Register some action that will be called precisely once, either when
 runResourceT is called, or when the ReleaseKey is passed to release.
Since 0.3.0
unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ())) Source #
Unprotect resource from cleanup actions; this allows you to send resource into another resourcet process and reregister it there. It returns a release action that should be run in order to clean resource or Nothing in case if resource is already freed.
Since 0.4.5