ContentsIndex
Framework.Pool
Description

This module describes an abstract pool of any connections (to DB, cache backend or anything). One will create a pool with

     pool <- emptyPool 20

(that opens 20 connections), and then

     (idx, pool) <- acquire someConfig connectFunction    -- Get open connection or create a new one
     doSomethingWith conn                                 
     free pool idx conn                                   -- Free a connection, so it may be used again by other threads
Synopsis
type Pool a = [PoolItem a]
type MPool a = MVar (Pool a)
emptyPool :: Int -> IO (MPool a)
acquire :: MPool a -> c -> (c -> IO a) -> IO (Int, a)
free :: MPool a -> Int -> a -> IO ()
freeAll :: MPool a -> (a -> IO ()) -> IO ()
garbageCollector :: MPool a -> (a -> IO ()) -> IO ()
Documentation
type Pool a = [PoolItem a]
Pool itself
type MPool a = MVar (Pool a)
Mutable pool
emptyPool :: Int -> IO (MPool a)
Return an empty pool with N items
acquire
::
=> MPool aPool
-> cSome data for connect
-> c -> IO aActual connect function
-> IO (Int, a)(Index in the pool, connection)
Get connection from pool
free
::
=> MPool aPool
-> IntIndex in the pool
-> aConnection
-> IO ()
Free connection
freeAll
::
=> MPool aPool
-> a -> IO ()Disconnect function
-> IO ()
Free (actually, disconnect) all connections in the pool
garbageCollector
::
=> MPool aPool
-> a -> IO ()Connection close function
-> IO ()
Run GC thread, which closes unused connections
Produced by Haddock version 2.4.2