| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Pool
Description
A simple resource pool implementation.
Use newPool to construct a resource Pool of a certain size and use withResource to acquire and release
resources.
Synopsis
- data Pool a = UnsafeMkPool {
- poolConfig :: !(PoolConfig a)
- poolSem :: QSem
- data PoolConfig a = MkPoolConfig {
- createResource :: IO a
- destroyResource :: a -> IO ()
- maxResources :: !Int
- defaultPoolConfig :: IO a -> (a -> IO ()) -> Int -> PoolConfig a
- newPool :: MonadIO m => PoolConfig a -> m (Pool a)
- withResource :: MonadUnliftIO m => Pool a -> (a -> m r) -> m r
A simple resource pool and its configuration
Constructors
| UnsafeMkPool | |
Fields
| |
data PoolConfig a Source #
a simple resource pool config
Constructors
| MkPoolConfig | |
Fields
| |
creating a pool
Arguments
| :: IO a | the action that creates a resource of type |
| -> (a -> IO ()) | the action that destroys a resource of type |
| -> Int | the maximum amount of used resources. It needs to be at lest 0 |
| -> PoolConfig a |
constructing a default PoolConfig
newPool :: MonadIO m => PoolConfig a -> m (Pool a) Source #
given a PoolConfig, create a new Pool
using a resource from a pool
withResource :: MonadUnliftIO m => Pool a -> (a -> m r) -> m r Source #
acquire a resource from a pool and run an action on it