packages feed

servant-pool (empty) → 0.1

raw patch · 4 files changed

+104/−0 lines, 4 filesdep +basedep +resource-pooldep +servantsetup-changed

Dependencies added: base, resource-pool, servant, time

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Alp Mestanogullari++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 Alp Mestanogullari 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
+ servant-pool.cabal view
@@ -0,0 +1,26 @@+name:                servant-pool+version:             0.1+synopsis:            Utility functions for creating servant 'Context's with "context/connection pooling" support+description:         Utility functions for creating servant 'Context's with "context/connection pooling" support+                     .+                     This package relies on the excellent <http://hackage.haskell.org/package/resource-pool resource-pool> library.+homepage:            http://github.com/zalora/servant-pool+license:             BSD3+license-file:        LICENSE+author:              Alp Mestanogullari+maintainer:          alp@zalora.com+copyright:           2014 Zalora SEA+category:            Web+build-type:          Simple+cabal-version:       >=1.10++library+  exposed-modules:     Servant.Context.Pool+  build-depends:       +      base >=4 && <5+    , servant >= 0.1+    , resource-pool >= 0.2+    , time >= 1.4+  hs-source-dirs:      src+  default-language:    Haskell2010+  ghc-options:         -Wall
+ src/Servant/Context/Pool.hs view
@@ -0,0 +1,46 @@+{- |+Module      :  Servant.Context.Pool+Copyright   :  (c) Zalora SEA 2014+License     :  BSD3+Maintainer  :  Alp Mestanogullari <alp@zalora.com>+Stability   :  experimental++Create /servant/ 'Context's with pooling support+using <http://hackage.haskell.org/package/resource-pool resource-pool>+-}+module Servant.Context.Pool+  ( pooledContext+  , contextOfPool+  , NominalDiffTime+  ) where++import Data.Pool (Pool, withResource, createPool)+import Data.Time.Clock (NominalDiffTime)+import Servant.Context++-- | Use this function to get a 'Context'+--   using a 'Pool' you already have around.+--   Note that the type in the 'Context' is not+--   @Pool c@ but just @c@. +--+--   It'll however use 'withResource' under the hood+--   to make a new connection available. That means+--   taking an unused one from the pool or bringing+--   a new one to life.+contextOfPool :: Pool c -> Context c+contextOfPool pool = mkContext (withResource pool)++-- | This is a handy function that lets you create the 'Context'+--   and the 'Pool' altogether. It just calls 'createPool' and+--   applies 'contextOfPool'.+pooledContext :: IO c            -- ^ Action that creates a new "connection"+			        -> (c -> IO ())    -- ^ Action that destroys an existing "connection"+              -> Int             -- ^ Number of stripes (sub-pools). /Minimum: 1/+              -> NominalDiffTime -- ^ Amount of time during which an unused+                                 --   "connection" is kept open+              -> Int             -- ^ Maximum number of resources to keep open+                                 --   per stripe. /Minimum: 1/+              -> IO (Context c)+pooledContext new destroy nstripes keepalive maxPerStripe =+  contextOfPool+    `fmap` createPool new destroy nstripes keepalive maxPerStripe