disposable 0.2.0.4 → 1.0.0.0
raw patch · 3 files changed
+50/−85 lines, 3 filesdep +stmdep −dlistdep ~ghcjs-base-stubPVP ok
version bump matches the API change (PVP)
Dependencies added: stm
Dependencies removed: dlist
Dependency ranges changed: ghcjs-base-stub
API changes (from Hackage documentation)
- Control.Disposable: [DisposeList] :: forall a. Disposable a => [a] -> SomeDisposable
- Control.Disposable: [DisposeNone] :: SomeDisposable
- Control.Disposable: [Dispose] :: forall a. Disposable a => a -> SomeDisposable
- Control.Disposable: class Disposable a
- Control.Disposable: class Disposing a where disposing x = DisposeList . toList . gDisposing $ from x
- Control.Disposable: class GDisposing f
- Control.Disposable: data SomeDisposable
- Control.Disposable: disposing :: (Disposing a, Generic a, GDisposing (Rep a)) => a -> SomeDisposable
- Control.Disposable: gDisposing :: GDisposing f => f p -> DList SomeDisposable
- Control.Disposable: instance (Control.Disposable.GDisposing f, Control.Disposable.GDisposing g) => Control.Disposable.GDisposing (f GHC.Generics.:*: g)
- Control.Disposable: instance (Control.Disposable.GDisposing f, Control.Disposable.GDisposing g) => Control.Disposable.GDisposing (f GHC.Generics.:+: g)
- Control.Disposable: instance Control.Disposable.Disposable (GHCJS.Foreign.Callback.Internal.Callback a)
- Control.Disposable: instance Control.Disposable.Disposable Control.Disposable.SomeDisposable
- Control.Disposable: instance Control.Disposable.Disposing (GHCJS.Foreign.Callback.Internal.Callback a)
- Control.Disposable: instance Control.Disposable.Disposing Control.Disposable.SomeDisposable
- Control.Disposable: instance Control.Disposable.Disposing Data.JSString.Internal.Type.JSString
- Control.Disposable: instance Control.Disposable.Disposing GHC.Types.Int
- Control.Disposable: instance Control.Disposable.Disposing GHCJS.Prim.JSVal
- Control.Disposable: instance Control.Disposable.Disposing a => Control.Disposable.Disposing (Data.DList.DList a)
- Control.Disposable: instance Control.Disposable.Disposing c => Control.Disposable.GDisposing (GHC.Generics.K1 i c)
- Control.Disposable: instance Control.Disposable.GDisposing GHC.Generics.U1
- Control.Disposable: instance Control.Disposable.GDisposing f => Control.Disposable.GDisposing (GHC.Generics.M1 i t f)
+ Control.Disposable: class Dispose a
+ Control.Disposable: data Disposable
+ Control.Disposable: instance Control.Disposable.Dispose (GHCJS.Foreign.Callback.Internal.Callback a)
+ Control.Disposable: instance Control.Disposable.Dispose (GHCJS.Foreign.Export.Export a)
+ Control.Disposable: instance Control.Disposable.Dispose Control.Disposable.Disposable
+ Control.Disposable: instance Control.Disposable.Dispose a => Control.Disposable.Dispose (Control.Concurrent.STM.TMVar.TMVar a)
+ Control.Disposable: instance Control.Disposable.Dispose a => Control.Disposable.Dispose (GHC.Conc.Sync.TVar a)
+ Control.Disposable: instance Control.Disposable.Dispose a => Control.Disposable.Dispose (GHC.IORef.IORef a)
+ Control.Disposable: instance Control.Disposable.Dispose a => Control.Disposable.Dispose (GHC.MVar.MVar a)
+ Control.Disposable: instance GHC.Base.Monoid Control.Disposable.Disposable
+ Control.Disposable: instance GHC.Base.Semigroup Control.Disposable.Disposable
+ Control.Disposable: runDisposable :: Disposable -> IO ()
- Control.Disposable: dispose :: Disposable a => a -> IO ()
+ Control.Disposable: dispose :: Dispose a => a -> Disposable
Files
- README.md +9/−1
- disposable.cabal +4/−4
- src/Control/Disposable.hs +37/−80
README.md view
@@ -1,5 +1,13 @@ [](https://hackage.haskell.org/package/disposable) [](http://travis-ci.org/louispan/disposable) -SomeDisposable aloows storing different resource releasing actions togther in a container.+Disposable allows storing different resource releasing actions togther in a container. This library is useful for queueing up GHCJS.Foreign.Callback together to be released after a new rendering frame.++# Changelog++* 1.0.0.0+ - Breaking changes:+ - Simplified by removing SomeDisposable GADT; Disposable is now a newtype, and the typeclass is called Dispose.+ - The intention is no longer to create Disposable instances for everything.+ - Disposable is only used to provide a safe wrapper around IO to ensure that it performs no other side effects.
disposable.cabal view
@@ -1,7 +1,7 @@ name: disposable-version: 0.2.0.4+version: 1.0.0.0 synopsis: Allows storing different resource-releasing actions together.-description: SomeDisposable allows storing different resource releasing actions togther in a container.+description: Disposable allows storing different resource releasing actions togther in a container. This library is useful for queueing up GHCJS.Foreign.Callback together to be released after a new rendering frame. homepage: https://github.com/louispan/disposable#readme@@ -20,12 +20,12 @@ hs-source-dirs: src exposed-modules: Control.Disposable build-depends: base >= 4.7 && < 5- , dlist >= 0.8 && < 0.9+ , stm >= 2.4.4.1 default-language: Haskell2010 if impl(ghcjs) build-depends: ghcjs-base if !impl(ghcjs)- build-depends: ghcjs-base-stub >= 0.1.0.2 && < 1+ build-depends: ghcjs-base-stub >= 0.1.0.2 source-repository head type: git
src/Control/Disposable.hs view
@@ -1,94 +1,51 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE DefaultSignatures #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE TypeOperators #-}--module Control.Disposable where+module Control.Disposable+ ( Disposable -- constructor not exported+ , runDisposable+ , Dispose(..)+ ) where -import qualified Data.DList as D-import Data.Foldable+import Control.Concurrent+import Control.Concurrent.STM+import Control.Monad+import Data.IORef import Data.Semigroup-import qualified GHC.Generics as G import qualified GHCJS.Foreign.Callback as J-import qualified GHCJS.Types as J---- | A 'Disposable' is something with some resources to release-class Disposable a where- dispose :: a -> IO ()--instance Disposable (J.Callback a) where- dispose = J.releaseCallback---- | Allows storing 'Disposable's in a heterogenous container-data SomeDisposable where- DisposeNone :: SomeDisposable- Dispose :: forall a. Disposable a => a -> SomeDisposable- DisposeList :: forall a. Disposable a => [a] -> SomeDisposable--instance Disposable SomeDisposable where- dispose DisposeNone = pure ()- dispose (Dispose a) = dispose a- dispose (DisposeList as) = traverse_ dispose as---- | Allow generic deriving instances of things that can be made into 'SomeDisposable'--- If a data type derives from Generic, and only contain instances of Disposing,--- then it can also be made an instance of 'Disposing'.--- Eg.--- @--- import Glazier.React as R--- import GHCJS.Foreign.Callback as J--- import GHC.Generics as G------ data Plan = Plan--- { _component :: R.ReactComponent--- , _onRender :: J.Callback (J.JSVal -> IO J.JSVal)--- ...--- } deriving G.Generic--- instance Disposing Plan--- @-class Disposing a where- disposing :: a -> SomeDisposable- default disposing :: (G.Generic a, GDisposing (G.Rep a)) => a -> SomeDisposable- disposing x = DisposeList . D.toList . gDisposing $ G.from x--instance Disposing SomeDisposable where- disposing = id+import qualified GHCJS.Foreign.Export as J -instance Disposing (J.Callback a) where- disposing = Dispose+-- | A wrapper around authorized IO actions.+newtype Disposable = Disposable { runDisposable :: IO () } -instance Disposing Int where- disposing _ = DisposeNone+instance Semigroup Disposable where+ (Disposable f) <> (Disposable g) = Disposable (f >> g) -instance Disposing J.JSString where- disposing _ = DisposeNone+instance Monoid Disposable where+ mempty = Disposable (pure ())+ mappend = (<>) -instance Disposing J.JSVal where- disposing _ = DisposeNone+-- | A 'Dispose' is something with some resources to release+class Dispose a where+ dispose :: a -> Disposable -instance Disposing a => Disposing (D.DList a) where- disposing xs = DisposeList $ disposing <$> D.toList xs+instance Dispose Disposable where+ dispose = id --- | Generic instance basically traverses the data type structure--- and expects the values to be all instances of 'Disposing'-class GDisposing f where- gDisposing :: f p -> D.DList SomeDisposable+instance Dispose (J.Callback a) where+ dispose = Disposable . J.releaseCallback -instance GDisposing G.U1 where- gDisposing G.U1 = mempty+instance Dispose (J.Export a) where+ dispose = Disposable . J.releaseExport -instance (GDisposing f, GDisposing g) => GDisposing (f G.:+: g) where- gDisposing (G.L1 x) = gDisposing x- gDisposing (G.R1 x) = gDisposing x+instance Dispose a => Dispose (TVar a) where+ dispose a = Disposable . join $ (runDisposable . dispose) <$> atomically (readTVar a) -instance (GDisposing f, GDisposing g) => GDisposing (f G.:*: g) where- gDisposing (x G.:*: y) = (gDisposing x) <> (gDisposing y)+instance Dispose a => Dispose (TMVar a) where+ dispose a = Disposable . join $+ (runDisposable . dispose) <$> atomically (readTMVar a) -instance (Disposing c) => GDisposing (G.K1 i c) where- gDisposing (G.K1 x) = D.singleton $ disposing x+instance Dispose a => Dispose (IORef a) where+ dispose a = Disposable . join $+ (runDisposable . dispose) <$> readIORef a -instance (GDisposing f) => GDisposing (G.M1 i t f) where- gDisposing (G.M1 x) = gDisposing x+instance Dispose a => Dispose (MVar a) where+ dispose a = Disposable . join $+ (runDisposable . dispose) <$> readMVar a