Skip to content

Commit

Permalink
extend mkAutoUpdateThings for with-modify
Browse files Browse the repository at this point in the history
  • Loading branch information
khibino committed Dec 13, 2024
1 parent 943bd7c commit 2084b9b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions auto-update/Control/AutoUpdate/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

--------------------------------------------------------------------------------
Expand All @@ -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
Expand Down

0 comments on commit 2084b9b

Please sign in to comment.