Skip to content

Commit

Permalink
quasar: Add Eq and Hashable instances for DisposableVar
Browse files Browse the repository at this point in the history
  • Loading branch information
queezle42 committed Feb 22, 2024
1 parent 5d5e0ef commit 3425bb0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions quasar/src/Quasar/Resources/DisposableVar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Quasar.Resources.DisposableVar (
) where

import Control.Monad.Catch
import Data.Hashable (Hashable(..))
import Quasar.Future (Future, ToFuture(..), IsFuture(..))
import Quasar.Prelude
import Quasar.Resources.Disposer
Expand All @@ -38,6 +39,13 @@ instance IsDisposerElement (DisposableVar a) where
instance Disposable (DisposableVar a) where
getDisposer x = mkDisposer [x]

instance Eq (DisposableVar a) where
(DisposableVar x _) == (DisposableVar y _) = x == y

instance Hashable (DisposableVar a) where
hash (DisposableVar key _) = hash key
hashWithSalt salt (DisposableVar key _) = hashWithSalt salt key

wrapDisposeException :: MonadCatch m => m a -> m a
wrapDisposeException fn = fn `catchAll` \ex -> throwM (DisposeException ex)

Expand Down Expand Up @@ -104,6 +112,14 @@ instance IsFuture () (TDisposableVar a) where
TDisposableVarDisposing callbackRegistry -> Left <$> registerCallback callbackRegistry callback
TDisposableVarAlive _ _ callbackRegistry -> Left <$> registerCallback callbackRegistry callback


instance Eq (TDisposableVar a) where
(TDisposableVar x _) == (TDisposableVar y _) = x == y

instance Hashable (TDisposableVar a) where
hash (TDisposableVar key _) = hash key
hashWithSalt salt (TDisposableVar key _) = hashWithSalt salt key

newTDisposableVar :: MonadSTMc NoRetry '[] m => a -> (a -> STMc NoRetry '[] ()) -> m (TDisposableVar a)
newTDisposableVar content disposeFn = liftSTMc do
key <- newUniqueSTM
Expand Down

0 comments on commit 3425bb0

Please sign in to comment.