From 2084b9ba3f582433e9d31d0efe578ea1a0107ae1 Mon Sep 17 00:00:00 2001 From: Kei Hibino Date: Fri, 13 Dec 2024 20:24:59 +0900 Subject: [PATCH] extend mkAutoUpdateThings for with-modify --- auto-update/Control/AutoUpdate/Internal.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/auto-update/Control/AutoUpdate/Internal.hs b/auto-update/Control/AutoUpdate/Internal.hs index 385546127..b4117437c 100644 --- a/auto-update/Control/AutoUpdate/Internal.hs +++ b/auto-update/Control/AutoUpdate/Internal.hs @@ -110,8 +110,13 @@ mkClosableAutoUpdate' = mkAutoUpdateThings (,,) mkAutoUpdateThings :: (IO a -> IO () -> UpdateState a -> b) -> UpdateSettings a -> IO b -mkAutoUpdateThings mk settings = do - us <- openUpdateState settings +mkAutoUpdateThings mk settings@UpdateSettings{..} = + mkAutoUpdateThingsWithModify mk settings (const updateAction) + +mkAutoUpdateThingsWithModify + :: (IO a -> IO () -> UpdateState a -> b) -> UpdateSettings a -> (a -> IO a) -> IO b +mkAutoUpdateThingsWithModify mk settings update1 = do + us <- openUpdateState settings update1 pure $ mk (getUpdateResult us) (closeUpdateState us) us -------------------------------------------------------------------------------- @@ -133,10 +138,10 @@ mkDeleteTimeout thc micro = do key <- registerTimeout mgr micro (atomically $ writeTVar thc True) pure $ unregisterTimeout mgr key -openUpdateState :: UpdateSettings a -> IO (UpdateState a) -openUpdateState UpdateSettings{..} = do +openUpdateState :: UpdateSettings a -> (a -> IO a) -> IO (UpdateState a) +openUpdateState UpdateSettings{..} update1 = do thc <- newTVarIO False - UpdateState (const updateAction) + UpdateState update1 <$> (newIORef =<< updateAction) <*> pure updateFreq <*> pure thc