diff --git a/src/Quasar/Disposable.hs b/src/Quasar/Disposable.hs index aa2c6c877aec781b04001eeb5e0e502e562b3111..8a4b1a2b32c1fd8616bf955dc641d1714e51abbd 100644 --- a/src/Quasar/Disposable.hs +++ b/src/Quasar/Disposable.hs @@ -406,15 +406,17 @@ attachDisposeAction resourceManager action = liftIO $ mask_ $ do attachDisposeAction_ :: MonadIO m => ResourceManager -> IO (Awaitable ()) -> m () attachDisposeAction_ resourceManager action = void $ attachDisposeAction resourceManager action --- | Start disposing a resource but instead of waiting for the operation to complete, pass the responsibility to a `ResourceManager`. +-- | Start disposing a resource but instead of waiting for the operation to complete, pass the responsibility to a +-- `MonadResourceManager`. -- --- The synchronous part of the `dispose`-Function will be run immediately but the resulting `Awaitable` will be passed to the resource manager. -disposeEventually :: (IsDisposable a, MonadIO m) => ResourceManager -> a -> m () -disposeEventually resourceManager disposable = liftIO $ do +-- The synchronous part of the `dispose`-Function will be run immediately but the resulting `Awaitable` will be passed +-- to the resource manager. +disposeEventually :: (IsDisposable a, MonadResourceManager m) => a -> m () +disposeEventually disposable = do disposeCompleted <- dispose disposable peekAwaitable disposeCompleted >>= \case Just () -> pure () - Nothing -> attachDisposable resourceManager disposable + Nothing -> registerDisposable disposable diff --git a/src/Quasar/Observable.hs b/src/Quasar/Observable.hs index ea1d06d63b4aeded94cfe942bb2f1b167ffd7eca..a002d51cf680d36856723923f50f53fe646312c6 100644 --- a/src/Quasar/Observable.hs +++ b/src/Quasar/Observable.hs @@ -249,8 +249,9 @@ instance IsObservable r (BindObservable r) where oldDisposable <- takeTMVar disposableVar -- IO action that will run after the STM transaction - pure $ do - disposeEventually resourceManager oldDisposable + pure do + onResourceManager resourceManager do + disposeEventually oldDisposable disposable <- unmask (outerMessageHandler key observableMessage) @@ -316,8 +317,9 @@ instance IsObservable r (CatchObservable e r) where oldDisposable <- takeTMVar disposableVar -- IO action that will run after the STM transaction - pure $ do - disposeEventually resourceManager oldDisposable + pure do + onResourceManager resourceManager do + disposeEventually oldDisposable disposable <- unmask (outerMessageHandler key observableMessage)