context-resource 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+44/−19 lines, 5 filesdep +exceptionsdep ~contextPVP ok
version bump matches the API change (PVP)
Dependencies added: exceptions
Dependency ranges changed: context
API changes (from Hackage documentation)
- Context.Resource: data Provider res
+ Context.Resource: data Provider m res
- Context.Resource: shareResource :: Provider res -> res -> IO a -> IO a
+ Context.Resource: shareResource :: forall m res a. (MonadIO m, MonadMask m) => Provider m res -> res -> m a -> m a
- Context.Resource: withProvider :: (forall r. (res -> IO r) -> IO r) -> (Provider res -> IO a) -> IO a
+ Context.Resource: withProvider :: forall m res a. (MonadIO m, MonadMask m) => (forall r. (res -> m r) -> m r) -> (Provider m res -> m a) -> m a
- Context.Resource: withResource :: Provider res -> (res -> IO a) -> IO a
+ Context.Resource: withResource :: forall m res a. (MonadIO m, MonadThrow m) => Provider m res -> (res -> m a) -> m a
- Context.Resource: withSharedResource :: Provider res -> (res -> IO a) -> IO a
+ Context.Resource: withSharedResource :: forall m res a. (MonadIO m, MonadMask m) => Provider m res -> (res -> m a) -> m a
Files
- CHANGELOG.md +8/−1
- README.md +0/−2
- context-resource.cabal +4/−5
- library/Context/Resource.hs +29/−9
- package.yaml +3/−2
CHANGELOG.md view
@@ -1,5 +1,12 @@ # Change log +## 0.2.0.0++* Lift signatures from `IO` to `MonadIO`, `MonadThrow` and `MonadMask`+* Type parameter order is now explicit via `ScopedTypeVariables`+* `WithRes` has new monad type parameter+* Dependency bump: `context-0.2.0.0`+ ## 0.1.0.0 -Initial release+* Initial release
README.md view
@@ -2,8 +2,6 @@ [![Version badge][]][version] -🚧 This README is under construction and could use some love. 🚧- `context-resource` contains a thread-safe, pool-compatible resource provider abstraction that supports resource-sharing within nested actions.
context-resource.cabal view
@@ -1,13 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack------ hash: 25e9584bac69d5f10c59d16e951839e19321a6ec9958b9edf594a1256b310ff9 name: context-resource-version: 0.1.0.0+version: 0.2.0.0 synopsis: Thread-safe, pool-compatible resource provider description: A thread-safe, pool-compatible resource provider abstraction that supports resource-sharing within nested actions.@@ -41,7 +39,8 @@ ghc-options: -Wall -fwarn-tabs -Wincomplete-uni-patterns -Wredundant-constraints build-depends: base >=4.12 && <5- , context >=0.1.0.0 && <0.2+ , context >=0.2.0.0 && <0.3+ , exceptions >=0.10.0 && <0.11 default-language: Haskell2010 test-suite context-resource-test-suite
library/Context/Resource.hs view
@@ -20,17 +20,19 @@ , withSharedResource ) where +import Control.Monad.Catch (MonadMask, MonadThrow)+import Control.Monad.IO.Class (MonadIO) import Prelude import qualified Context -- | An opaque resource provider. -- -- @since 0.1.0.0-newtype Provider res = Provider- { store :: Context.Store (WithRes res)+newtype Provider m res = Provider+ { store :: Context.Store (WithRes m res) } -newtype WithRes res = WithRes (forall r. (res -> IO r) -> IO r)+newtype WithRes m res = WithRes (forall r. (res -> m r) -> m r) -- | Given a @with@-style function to acquire a resource, supplies the caller -- with a resource 'Provider'. This 'Provider' should ideally be long-lived and@@ -39,9 +41,11 @@ -- -- @since 0.1.0.0 withProvider- :: (forall r. (res -> IO r) -> IO r)- -> (Provider res -> IO a)- -> IO a+ :: forall m res a+ . (MonadIO m, MonadMask m)+ => (forall r. (res -> m r) -> m r)+ -> (Provider m res -> m a)+ -> m a withProvider withRes f = do Context.withStore Context.noPropagation (Just (WithRes withRes)) \store -> do f Provider { store }@@ -50,7 +54,12 @@ -- specified action. -- -- @since 0.1.0.0-withResource :: Provider res -> (res -> IO a) -> IO a+withResource+ :: forall m res a+ . (MonadIO m, MonadThrow m)+ => Provider m res+ -> (res -> m a)+ -> m a withResource Provider { store } f = do WithRes withRes <- Context.mine store withRes f@@ -60,7 +69,13 @@ -- 'withSharedResource') within the action will return the shared resource. -- -- @since 0.1.0.0-shareResource :: Provider res -> res -> IO a -> IO a+shareResource+ :: forall m res a+ . (MonadIO m, MonadMask m)+ => Provider m res+ -> res+ -> m a+ -> m a shareResource Provider { store } resource action = do Context.use store (WithRes ($ resource)) action @@ -71,7 +86,12 @@ -- This is a convenience function combining 'withResource' and 'shareResource'. -- -- @since 0.1.0.0-withSharedResource :: Provider res -> (res -> IO a) -> IO a+withSharedResource+ :: forall m res a+ . (MonadIO m, MonadMask m)+ => Provider m res+ -> (res -> m a)+ -> m a withSharedResource provider f = do withResource provider \resource -> do shareResource provider resource do
package.yaml view
@@ -1,5 +1,5 @@ name: context-resource-version: '0.1.0.0'+version: '0.2.0.0' github: "jship/context/context-resource" license: MIT license-file: LICENSE.md@@ -27,7 +27,8 @@ library: dependencies: - base >=4.12 && <5- - context >=0.1.0.0 && <0.2+ - context >=0.2.0.0 && <0.3+ - exceptions >=0.10.0 && <0.11 source-dirs: library tests: