Skip to content

Commit

Permalink
define runMasterHandler locally; hlint
Browse files Browse the repository at this point in the history
  • Loading branch information
softmechanics committed Nov 27, 2010
1 parent 0afaa91 commit 4a900d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 10 additions & 8 deletions Yesod/Continuation.hs
Expand Up @@ -27,6 +27,7 @@ import Data.Hashable
import Data.HashMap (HashMap)
import qualified Data.HashMap as H
import Data.DateTime
import Data.Maybe (fromMaybe)
import Control.Applicative
import Control.Concurrent.STM
import Control.Monad
Expand Down Expand Up @@ -85,9 +86,7 @@ continuationsOnRequest = runMasterHandler $ contToMasterHandler $ do
let interval = contPruneInterval cont
tcount = contTCounter cont
clean <- liftIO $ atomically $ checkCounter interval tcount
if clean
then expireContSessions
else return ()
when clean expireContSessions

-- | Exported Generic Site Handlers

Expand All @@ -97,7 +96,7 @@ addContinuation hndl = contToSubHandler $ addContinuationI hndl

-- | continuation routes registered in current session
continuationRoutes :: YesodContinuations y => GHandler sub y [Route y]
continuationRoutes = contToSubHandler $ continuationRoutesI
continuationRoutes = contToSubHandler continuationRoutesI


--------------------------------------------------
Expand All @@ -124,9 +123,7 @@ continuationRoutesI = do
getContR :: Yesod y => ContKey -> ContHandler y ChooseRep
getContR cid = do
cont <- popCont cid
runMasterHandler $ case cont of
Just hndl -> hndl
Nothing -> notFound
runMasterHandler $ fromMaybe notFound cont

getContinuations :: YesodContinuations y => GHandler s y (Continuations y)
getContinuations = yesodContinuations <$> getYesod
Expand Down Expand Up @@ -178,7 +175,7 @@ expireContSessions = do
let sessions = H.toList cm
sessions' <- filterM (notExpired t . snd) sessions
writeTVar tcm $ H.fromList sessions'
return $ (length sessions) - (length sessions')
return $ length sessions - length sessions'
putStrLn $ "deleted " ++ show deleted ++ " continuation sessions"

getContMap :: ContHandler y (TContMap y)
Expand Down Expand Up @@ -266,3 +263,8 @@ popCont ckey = do
m' = H.delete ckey m
writeTVar scm m'
return hndl

-- | convert a master site handler to a subsite handler
runMasterHandler :: GHandler master master a -> GHandler sub master a
runMasterHandler = toMasterHandlerMaybe id id Nothing

3 changes: 1 addition & 2 deletions testcont.hs
@@ -1,5 +1,4 @@
{-# LANGUAGE QuasiQuotes
, TemplateHaskell
, MultiParamTypeClasses
, TypeFamilies
, FlexibleInstances
Expand Down Expand Up @@ -37,7 +36,7 @@ instance YesodSubRoute (Continuations Test) Test where

getRootR :: GHandler Test Test RepHtml
getRootR = do
t <- liftIO $ getCurrentTime
t <- liftIO getCurrentTime
addContinuation $ dateTimeHtml t
addContinuation $ dateTimeJson t
routes <- continuationRoutes
Expand Down

0 comments on commit 4a900d5

Please sign in to comment.