ex-pool-0.2.1: Another fork of resource-pool, with a MonadIO and MonadCatch constraint

Copyright(c) 2013 Kim Altintop (c) 2011 MailRank Inc.
LicenseBSD3
MaintainerKim Altintop <kim.altintop@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Data.Pool

Description

A high-performance striped pooling abstraction for managing flexibly-sized collections of resources such as database connections.

This module is based on resource-pool. For more comprehensive documentation, please refer to the original package: http://hackage.haskell.org/package/resource-pool

Synopsis

Documentation

data Pool a Source #

Instances

Show (Pool a) Source # 

Methods

showsPrec :: Int -> Pool a -> ShowS #

show :: Pool a -> String #

showList :: [Pool a] -> ShowS #

createPool Source #

Arguments

:: IO a

Action to create a new resource

-> (a -> IO ())

Action to destroy a resource

-> Word32

Stripe count

-> NominalDiffTime

Amount of time after which an unused resource can be released

-> Word32

Maximum number of resources per stripe

-> IO (Pool a) 

destroyResource :: MonadIO m => Pool a -> LocalPool a -> a -> m () Source #

purgePool :: Pool a -> IO () Source #

Destroys all resources currently not in use and removes them from the pool.

Note that resources are automatically released when the Pool is garbage-collected. This function is however useful in situations where a Pool is explicitly discarded and resources should be freed immediately.

putResource :: MonadIO m => LocalPool a -> a -> m () Source #

takeResource :: MonadIO m => Pool a -> m (a, LocalPool a) Source #

tryTakeResource :: MonadIO m => Pool a -> m (Maybe (a, LocalPool a)) Source #

A non-blocking version of takeResource. The tryTakeResource function returns immediately, with Nothing if the pool is exhausted, or Just (a, LocalPool a) if a resource could be borrowed from the pool successfully.

tryWithResource :: (MonadIO m, MonadMask m) => Pool a -> (a -> m b) -> m (Maybe b) Source #

Similar to withResource, but only performs the action if a resource could be taken from the pool without blocking. Otherwise, tryWithResource returns immediately with Nothing (ie. the action function is not called). Conversely, if a resource can be borrowed from the pool without blocking, the action is performed and it's result is returned, wrapped in a Just.

withResource :: (MonadIO m, MonadMask m) => Pool a -> (a -> m b) -> m b Source #