unliftio-pool (empty) → 0.1.0.0
raw patch · 4 files changed
+109/−0 lines, 4 filesdep +basedep +resource-pooldep +timesetup-changed
Dependencies added: base, resource-pool, time, transformers, unliftio-core
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- src/Unlift/Pool.hs +52/−0
- unliftio-pool.cabal +25/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2018, Bardur Arantsson++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Bardur Arantsson nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Unlift/Pool.hs view
@@ -0,0 +1,52 @@+module Unlift.Pool+ ( Pool+ , LocalPool+ , createPool+ , withResource+ , takeResource+ , tryWithResource+ , tryTakeResource+ , destroyResource+ , putResource+ , destroyAllResources+ ) where++import Control.Monad.IO.Unlift (MonadUnliftIO(..), liftIO)+import qualified Data.Pool as P+import Data.Time.Clock (NominalDiffTime)++type Pool = P.Pool++type LocalPool = P.LocalPool++createPool :: MonadUnliftIO m => m a -> (a -> m ()) -> Int -> NominalDiffTime -> Int -> m (Pool a)+createPool create destroy stripes keepAlive maxPerStripe =+ withRunInIO $ \io ->+ liftIO $ P.createPool (io create) (io . destroy) stripes keepAlive maxPerStripe++withResource :: MonadUnliftIO m => Pool a -> (a -> m b) -> m b+withResource pool action =+ withRunInIO $ \io ->+ liftIO $ withResource pool $ \a ->+ io $ action a++takeResource :: MonadUnliftIO m => Pool a -> m (a, LocalPool a)+takeResource pool = liftIO $ P.takeResource pool++tryWithResource :: MonadUnliftIO m => Pool a -> (a -> m b) -> m (Maybe b)+tryWithResource pool action =+ withRunInIO $ \io ->+ liftIO $ P.tryWithResource pool $ \a ->+ io $ action a++tryTakeResource :: MonadUnliftIO m => Pool a -> m (Maybe (a, LocalPool a))+tryTakeResource pool = liftIO $ P.tryTakeResource pool++destroyResource :: MonadUnliftIO m => Pool a -> LocalPool a -> a -> m ()+destroyResource pool localPool a = liftIO $ P.destroyResource pool localPool a++putResource :: MonadUnliftIO m => LocalPool a -> a -> m ()+putResource localPool a = liftIO $ P.putResource localPool a++destroyAllResources :: MonadUnliftIO m => Pool a -> m ()+destroyAllResources pool = liftIO $ P.destroyAllResources pool
+ unliftio-pool.cabal view
@@ -0,0 +1,25 @@+name: unliftio-pool+version: 0.1.0.0+synopsis: Data.Pool generalized to MonadUnliftIO.+description: This is a generalization of Data.Pool to MonadUnliftIO.+license: BSD3+license-file: LICENSE+author: Bardur Arantsson+maintainer: Bardur Arantsson <bardur@scientician.net>+category: Control, Data, Database, Network+build-type: Simple+cabal-version: >=1.10++source-repository head+ type: git+ location: https://github.com/BardurArantsson/unliftio-pool++library+ exposed-modules: Unlift.Pool+ build-depends: base >= 4.10 && < 4.11+ , resource-pool >= 0.2.3.2 && < 0.3+ , time >= 1.8 && < 2+ , transformers >= 0.5 && < 0.6+ , unliftio-core >= 0.1.1 && < 0.2+ hs-source-dirs: src+ default-language: Haskell2010