finallyHandler
This commit is contained in:
parent
1708d804ea
commit
9158268904
@ -73,6 +73,7 @@ module Yesod.Handler
|
|||||||
, YesodApp (..)
|
, YesodApp (..)
|
||||||
, toMasterHandler
|
, toMasterHandler
|
||||||
, localNoCurrent
|
, localNoCurrent
|
||||||
|
, finallyHandler
|
||||||
#if TEST
|
#if TEST
|
||||||
, testSuite
|
, testSuite
|
||||||
#endif
|
#endif
|
||||||
@ -94,6 +95,7 @@ import Control.Monad.Trans.Class
|
|||||||
import Control.Monad.Trans.Writer
|
import Control.Monad.Trans.Writer
|
||||||
import Control.Monad.Trans.Reader
|
import Control.Monad.Trans.Reader
|
||||||
import "MonadCatchIO-transformers" Control.Monad.CatchIO (MonadCatchIO)
|
import "MonadCatchIO-transformers" Control.Monad.CatchIO (MonadCatchIO)
|
||||||
|
import qualified "MonadCatchIO-transformers" Control.Monad.CatchIO as C
|
||||||
|
|
||||||
import System.IO
|
import System.IO
|
||||||
import qualified Network.Wai as W
|
import qualified Network.Wai as W
|
||||||
@ -108,7 +110,6 @@ import Test.Framework (testGroup, Test)
|
|||||||
import Test.Framework.Providers.HUnit (testCase)
|
import Test.Framework.Providers.HUnit (testCase)
|
||||||
import Test.HUnit hiding (Test)
|
import Test.HUnit hiding (Test)
|
||||||
import Yesod.Content hiding (testSuite)
|
import Yesod.Content hiding (testSuite)
|
||||||
import "MonadCatchIO-transformers" Control.Monad.CatchIO (finally)
|
|
||||||
import Data.IORef
|
import Data.IORef
|
||||||
#else
|
#else
|
||||||
import Yesod.Content
|
import Yesod.Content
|
||||||
@ -480,7 +481,7 @@ testSuite = testGroup "Yesod.Handler"
|
|||||||
caseFinally :: Assertion
|
caseFinally :: Assertion
|
||||||
caseFinally = do
|
caseFinally = do
|
||||||
i <- newIORef (1 :: Int)
|
i <- newIORef (1 :: Int)
|
||||||
let h = finally (do
|
let h = finallyHandler (do
|
||||||
liftIO $ writeIORef i 2
|
liftIO $ writeIORef i 2
|
||||||
() <- redirectString RedirectTemporary ""
|
() <- redirectString RedirectTemporary ""
|
||||||
return ()) $ liftIO $ writeIORef i 3
|
return ()) $ liftIO $ writeIORef i 3
|
||||||
@ -490,3 +491,8 @@ caseFinally = do
|
|||||||
j @?= 3
|
j @?= 3
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
-- | A version of 'finally' which works correctly with short-circuiting.
|
||||||
|
finallyHandler :: GHandler s m a -> GHandler s m b -> GHandler s m a
|
||||||
|
finallyHandler (GHandler (ReaderT thing)) (GHandler (ReaderT after)) =
|
||||||
|
GHandler $ ReaderT $ \hd -> mapMEitherT (`C.finally` runMEitherT (after hd)) (thing hd)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod
|
name: yesod
|
||||||
version: 0.5.3
|
version: 0.5.4
|
||||||
license: BSD3
|
license: BSD3
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user