Safe Haskell | None |
---|---|
Language | Haskell2010 |
Resource management via MonadResource
.
Synopsis
- data Resource
- runResource :: Eff (Resource ': es) a -> Eff es a
- allocate :: MonadResource m => IO a -> (a -> IO ()) -> m (ReleaseKey, a)
- allocate_ :: MonadResource m => IO a -> IO () -> m ReleaseKey
- register :: MonadResource m => IO () -> m ReleaseKey
- release :: MonadIO m => ReleaseKey -> m ()
- unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ()))
Documentation
Registering and releasing resources
:: 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
register
ing the release action, but this properly handles masking of
asynchronous exceptions.
Since 0.3.0
:: MonadResource m | |
=> IO a | allocate |
-> IO () | free resource |
-> m ReleaseKey |
Perform some allocation where the return value is not required, and automatically register a cleanup action.
allocate_
is to allocate
as bracket_
is to bracket
This is almost identical to calling the allocation and then
register
ing the release action, but this properly handles masking of
asynchronous exceptions.
Since: resourcet-1.2.4
register :: MonadResource m => IO () -> m ReleaseKey #
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
release :: MonadIO m => ReleaseKey -> m () #
Call a release action early, and deregister it from the list of cleanup actions to be performed.
Since 0.3.0
unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ())) #
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