diff --git a/src/Quasar/ResourceManager.hs b/src/Quasar/ResourceManager.hs index 7bedb8405043d19dd236da29ea09a8012a1c2e7b..6f22bb72bc6ea96bc3cf3bf933097f420989da96 100644 --- a/src/Quasar/ResourceManager.hs +++ b/src/Quasar/ResourceManager.hs @@ -8,6 +8,8 @@ module Quasar.ResourceManager ( registerNewResource_, registerDisposable, registerDisposeAction, + withScopedResourceManager, + withScopedResourceManagerIO, withSubResourceManagerM, onResourceManager, captureDisposable, @@ -140,11 +142,17 @@ registerNewResource action = mask_ do registerNewResource_ :: (IsDisposable a, MonadResourceManager m) => m a -> m () registerNewResource_ action = void $ registerNewResource action +withScopedResourceManager :: MonadResourceManager m => m a -> m a +withScopedResourceManager action = + bracket newResourceManager dispose \scope -> localResourceManager scope action + +withScopedResourceManagerIO :: MonadResourceManager m => ResourceManagerIO a -> m a +withScopedResourceManagerIO action = + bracket newResourceManager dispose \scope -> onResourceManager scope action --- TODO rename to withResourceScope, subResourceManager or withResourceManager? withSubResourceManagerM :: MonadResourceManager m => m a -> m a -withSubResourceManagerM action = - bracket newResourceManager dispose \scope -> localResourceManager scope action +withSubResourceManagerM = withScopedResourceManager +{-# DEPRECATED withSubResourceManagerM "Use `withScopedResourceManager` instead." #-} type ResourceManagerT = ReaderT ResourceManager