This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "snap-core".
The branch, 0.3 has been updated
via 48a7537217220bf0399fc78b3dab94abae732bac (commit)
from 78767e487e5f8989ea65312f8246327454a2577c (commit)
Summary of changes:
src/Snap/Internal/Types.hs | 29 +++++++++++++++++++++++++++++
src/Snap/Types.hs | 1 +
2 files changed, 30 insertions(+), 0 deletions(-)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 48a7537217220bf0399fc78b3dab94abae732bac
Author: Carl Howells <[email protected]>
Date: Sun Jun 27 10:29:28 2010 -0700
Add a specialized version of bracket, which works properly with Snap
diff --git a/src/Snap/Internal/Types.hs b/src/Snap/Internal/Types.hs
index 0efbf09..aec7678 100644
--- a/src/Snap/Internal/Types.hs
+++ b/src/Snap/Internal/Types.hs
@@ -503,6 +503,35 @@ ipHeaderFilter' header = do
------------------------------------------------------------------------------
+-- | This function brackets a Snap action in resource acquisition and
+-- release. This is provided because MonadCatchIO's 'bracket' function
+-- doesn't work properly in the case of a short-circuit return from
+-- the action being bracketed.
+--
+-- In order to prevent confusion regarding the effects of the
+-- aquisition and release actions on the Snap state, this function
+-- doesn't accept Snap actions for the acquire or release actions.
+--
+-- This function will run the release action in all cases where the
+-- acquire action succeeded. This includes the following behaviors
+-- from the bracketed Snap action.
+--
+-- 1. Normal completion
+--
+-- 2. Short-circuit completion, either from calling 'fail' or 'finishWith'
+--
+-- 3. An exception being thrown.
+bracketSnap :: IO a -> (a -> IO b) -> (a -> Snap c) -> Snap c
+bracketSnap before after thing = Snap $ do
+ a <- liftIO before
+ let after' = liftIO $ after a
+ (Snap thing') = thing a
+ r <- unblock thing' `onException` after'
+ _ <- after'
+ return r
+
+
+------------------------------------------------------------------------------
-- | This exception is thrown if the handler you supply to 'runSnap' fails.
data NoHandlerException = NoHandlerException
deriving (Eq, Typeable)
diff --git a/src/Snap/Types.hs b/src/Snap/Types.hs
index 31344d8..b22a239 100644
--- a/src/Snap/Types.hs
+++ b/src/Snap/Types.hs
@@ -12,6 +12,7 @@ module Snap.Types
, NoHandlerException(..)
-- ** Functions for control flow and early termination
+ , bracketSnap
, finishWith
, pass
-----------------------------------------------------------------------
hooks/post-receive
--
snap-core
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap