{-# LANGUAGE CPP #-}

module Data.Pool.Compat
  ( module Data.Pool
  , createPool
  ) where

import Prelude

import Data.Pool hiding (createPool)
#if MIN_VERSION_resource_pool(0,3,0)
#else
import Control.Concurrent (getNumCapabilities)
import qualified Data.Pool as Pool
#endif

createPool
  :: IO a
  -> (a -> IO ())
  -> Double
  -> Int
  -> IO (Pool a)
createPool :: forall a. IO a -> (a -> IO ()) -> Double -> Int -> IO (Pool a)
createPool IO a
create a -> IO ()
destroy Double
timeout Int
size = do
#if MIN_VERSION_resource_pool(0,3,0)
  PoolConfig a -> IO (Pool a)
forall a. PoolConfig a -> IO (Pool a)
newPool (PoolConfig a -> IO (Pool a)) -> PoolConfig a -> IO (Pool a)
forall a b. (a -> b) -> a -> b
$ IO a -> (a -> IO ()) -> Double -> Int -> PoolConfig a
forall a. IO a -> (a -> IO ()) -> Double -> Int -> PoolConfig a
defaultPoolConfig IO a
create a -> IO ()
destroy Double
timeout Int
size
#else
  -- Re-implement instead of using the deprecated compatibility function, so
  -- that we can get a consistent numStripes and size behavior.
  numStripes <- getNumCapabilities
  Pool.createPool create destroy numStripes (realToFrac timeout) size
#endif