forked from yesodweb/persistent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
106 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "scripts"] | ||
path = scripts | ||
url = git://github.com/yesodweb/scripts.git | ||
[submodule "pool"] | ||
path = pool | ||
url = https://github.com/bos/pool.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#!/bin/bash | ||
|
||
pkgs=( ./pool | ||
./pool-conduit | ||
./persistent | ||
./persistent-template | ||
./persistent-sqlite | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
-- | Allocate resources from a pool, guaranteeing resource handling via the | ||
-- ResourceT transformer. | ||
module Data.Conduit.Pool | ||
( ManagedResource (..) | ||
, takeResource | ||
, takeResourceCheck | ||
, P.Pool | ||
, P.createPool | ||
, P.withResource | ||
) where | ||
|
||
import qualified Data.Pool as P | ||
import Control.Monad.Trans.Resource | ||
import Control.Monad.IO.Class (liftIO) | ||
import qualified Data.IORef as I | ||
|
||
-- | The result of taking a resource. | ||
data ManagedResource m a = ManagedResource | ||
{ mrValue :: a -- ^ The actual resource. | ||
, mrReuse :: Bool -> ResourceT m () | ||
-- ^ Let's you specify whether the resource should be returned to the pool | ||
-- (via 'P.putResource') or destroyed (via 'P.destroyResource') on release. | ||
-- This defaults to destruction, in case of exceptions. | ||
, mrRelease :: ResourceT m () | ||
-- ^ Release this resource, either destroying it or returning it to the | ||
-- pool. | ||
} | ||
|
||
-- | Take a resource from the pool and register a release action. | ||
takeResource :: ResourceIO m => P.Pool a -> ResourceT m (ManagedResource m a) | ||
takeResource pool = do | ||
onRelRef <- liftIO $ I.newIORef False | ||
(relKey, (a, _)) <- withIO | ||
(P.takeResource pool) | ||
(\(a, local) -> do | ||
onRel <- I.readIORef onRelRef | ||
if onRel | ||
then P.putResource local a | ||
else P.destroyResource pool local a) | ||
return ManagedResource | ||
{ mrValue = a | ||
, mrReuse = liftIO . I.writeIORef onRelRef | ||
, mrRelease = release relKey | ||
} | ||
|
||
-- | Same as 'takeResource', but apply some action to check if a resource is | ||
-- still valid. | ||
takeResourceCheck :: ResourceIO m | ||
=> P.Pool a | ||
-> (a -> ResourceT m Bool) | ||
-> ResourceT m (ManagedResource m a) | ||
takeResourceCheck pool check = do | ||
mr <- takeResource pool | ||
isValid <- check $ mrValue mr | ||
if isValid | ||
then return mr | ||
else do | ||
mrRelease mr | ||
takeResourceCheck pool check |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: pool-conduit | ||
version: 0.0.0 | ||
license: BSD3 | ||
license-file: LICENSE | ||
author: Michael Snoyman <[email protected]> | ||
maintainer: Michael Snoyman <[email protected]> | ||
synopsis: Resource pool allocations via ResourceT. | ||
description: Allocate resources from a pool, guaranteeing resource handling via the ResourceT transformer. | ||
category: Database, Yesod, Conduit | ||
stability: Stable | ||
cabal-version: >= 1.8 | ||
build-type: Simple | ||
homepage: http://www.yesodweb.com/book/persistent | ||
|
||
library | ||
|
||
build-depends: base >= 4 && < 5 | ||
, resource-pool >= 0.2.0.4 && < 0.3 | ||
, transformers >= 0.2.1 && < 0.3 | ||
, conduit >= 0.0.2 && < 0.1 | ||
|
||
exposed-modules: Data.Conduit.Pool | ||
|
||
ghc-options: -Wall | ||
|
||
source-repository head | ||
type: git | ||
location: git://github.com/yesodweb/persistent.git |
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.