From b9b2d0d609199dcdcb8b2f76182162b6df1bed1e Mon Sep 17 00:00:00 2001 From: David Turner Date: Fri, 13 Nov 2015 13:40:19 +0000 Subject: [PATCH] Use AutoUpdate for session expiry date too --- yesod-core/Yesod/Core/Internal/Session.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/yesod-core/Yesod/Core/Internal/Session.hs b/yesod-core/Yesod/Core/Internal/Session.hs index dd9ebc61..03240abf 100644 --- a/yesod-core/Yesod/Core/Internal/Session.hs +++ b/yesod-core/Yesod/Core/Internal/Session.hs @@ -16,6 +16,7 @@ import Control.Monad (forever, guard) import Yesod.Core.Types import Yesod.Core.Internal.Util import qualified Data.IORef as I +import Control.AutoUpdate encodeClientSession :: CS.Key -> CS.IV @@ -54,15 +55,15 @@ clientSessionDateCacher :: NominalDiffTime -- ^ Inactive session valitity. -> IO (IO ClientSessionDateCache, IO ()) clientSessionDateCacher validity = do - ref <- getUpdated >>= I.newIORef - tid <- forkIO $ forever (doUpdate ref) - return $! (I.readIORef ref, killThread tid) + getClientSessionDateCache <- mkAutoUpdate defaultUpdateSettings + { updateAction = getUpdated + , updateFreq = 10000000 -- 10s + } + + return $! (getClientSessionDateCache, return ()) where getUpdated = do now <- getCurrentTime let expires = validity `addUTCTime` now expiresS = runPut (putTime expires) return $! ClientSessionDateCache now expires expiresS - doUpdate ref = do - threadDelay 10000000 -- 10s - I.writeIORef ref =<< getUpdated