diff --git a/src/Quasar/Disposable.hs b/src/Quasar/Disposable.hs index 250abb5ae67868fe587638fb6437b58fa781e0af..b41564087a1d50039b86a1bb3d96552407e59a79 100644 --- a/src/Quasar/Disposable.hs +++ b/src/Quasar/Disposable.hs @@ -6,6 +6,7 @@ module Quasar.Disposable ( newDisposable, synchronousDisposable, noDisposable, + alreadyDisposing, -- ** ResourceManager ResourceManager, @@ -129,6 +130,19 @@ noDisposable = mempty data ResourceManager = ResourceManager +newtype AlreadyDisposing = AlreadyDisposing (Awaitable ()) + +instance IsDisposable AlreadyDisposing where + dispose x = pure (isDisposed x) + isDisposed (AlreadyDisposing awaitable) = awaitable + +-- | Create a `Disposable` from an `IsAwaitable`. +-- +-- The disposable is considered to be already disposing (so `dispose` will be a no-op) and is considered disposed once +-- the awaitable is completed. +alreadyDisposing :: IsAwaitable () a => a -> Disposable +alreadyDisposing someAwaitable = toDisposable $ AlreadyDisposing $ toAwaitable someAwaitable + class HasResourceManager a where getResourceManager :: a -> ResourceManager