Skip to content
Snippets Groups Projects
Commit 4b1e31f1 authored by Jens Nolte's avatar Jens Nolte
Browse files

Add helper functions for ResourceManagerSTM

parent f4a8f2a7
No related branches found
No related tags found
No related merge requests found
...@@ -12,12 +12,14 @@ module Quasar.ResourceManager ( ...@@ -12,12 +12,14 @@ module Quasar.ResourceManager (
registerAsyncDisposeAction, registerAsyncDisposeAction,
withScopedResourceManager, withScopedResourceManager,
onResourceManager, onResourceManager,
onResourceManagerSTM,
captureDisposable, captureDisposable,
captureDisposable_, captureDisposable_,
disposeOnError, disposeOnError,
liftResourceManagerIO, liftResourceManagerIO,
runInResourceManagerSTM, runInResourceManagerSTM,
enterResourceManager, enterResourceManager,
enterResourceManagerSTM,
lockResourceManager, lockResourceManager,
-- ** Top level initialization -- ** Top level initialization
...@@ -219,6 +221,9 @@ instance {-# OVERLAPS #-} MonadResourceManager (ResourceManagerT STM) where ...@@ -219,6 +221,9 @@ instance {-# OVERLAPS #-} MonadResourceManager (ResourceManagerT STM) where
onResourceManager :: (IsResourceManager a, MonadIO m) => a -> ResourceManagerIO r -> m r onResourceManager :: (IsResourceManager a, MonadIO m) => a -> ResourceManagerIO r -> m r
onResourceManager target action = liftIO $ runReaderT action (toResourceManager target) onResourceManager target action = liftIO $ runReaderT action (toResourceManager target)
onResourceManagerSTM :: (IsResourceManager a) => a -> ResourceManagerSTM r -> STM r
onResourceManagerSTM target action = runReaderT action (toResourceManager target)
liftResourceManagerIO :: (MonadResourceManager m, MonadIO m) => ResourceManagerIO r -> m r liftResourceManagerIO :: (MonadResourceManager m, MonadIO m) => ResourceManagerIO r -> m r
liftResourceManagerIO action = do liftResourceManagerIO action = do
resourceManager <- askResourceManager resourceManager <- askResourceManager
...@@ -254,6 +259,14 @@ enterResourceManager resourceManager action = liftIO do ...@@ -254,6 +259,14 @@ enterResourceManager resourceManager action = liftIO do
onResourceManager resourceManager $ lockResourceManager do onResourceManager resourceManager $ lockResourceManager do
action `catchAll` \ex -> liftIO $ throwToResourceManager resourceManager ex action `catchAll` \ex -> liftIO $ throwToResourceManager resourceManager ex
-- | Run a computation on a resource manager and throw any exception that occurs to the resource manager.
--
-- This can be used to run e.g. callbacks that belong to a different resource context.
enterResourceManagerSTM :: ResourceManager -> ResourceManagerSTM () -> STM ()
enterResourceManagerSTM resourceManager action = do
onResourceManagerSTM resourceManager do
action `catchAll` \ex -> throwToResourceManager ex
-- * Resource manager implementations -- * Resource manager implementations
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment