@@ -11,6 +11,13 @@ module Effectful.Resource
11 , R.register
11 , R.register
12 , R.release
12 , R.release
13 , R.unprotect
13 , R.unprotect
19+ , R.createInternalState
20+ , R.closeInternalState
16import Control.Exception
23import Control.Exception
@@ -40,6 +47,24 @@ runResource m = unsafeEff $ \es0 -> do
40 RI.stateCleanupChecked Nothing istate
47 RI.stateCleanupChecked Nothing istate
50+----------------------------------------
53+-- | Get the 'R.InternalState' of the current 'Resource' effect.
54+getInternalState :: Resource :> es => Eff es R.InternalState
56+ IdE (Resource istate) <- getEffect
59+-- | Run the 'Resource' effect with existing 'R.InternalState'.
61+-- /Note:/ the 'R.InternalState' will not be closed at the end.
62+runInternalState :: R.InternalState -> Eff (Resource : es) a -> Eff es a
63+runInternalState istate = evalEffect $ IdE (Resource istate)
65+----------------------------------------
43instance (IOE :> es, Resource :> es) => R.MonadResource (Eff es) where
68instance (IOE :> es, Resource :> es) => R.MonadResource (Eff es) where
44 liftResourceT (RI.ResourceT m) = unsafeEff $ \es -> do
69 liftResourceT (RI.ResourceT m) = unsafeEff $ \es -> do
45 getEnv es >>= \(IdE (Resource istate)) -> m istate
70 getEnv es >>= \(IdE (Resource istate)) -> m istate