Skip to content

Commit

Permalink
add prev-value arg to usUpdateAction_
Browse files Browse the repository at this point in the history
  • Loading branch information
khibino committed Dec 13, 2024
1 parent 7f44618 commit 943bd7c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions auto-update/Control/AutoUpdate/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ mkAutoUpdateThings mk settings = do
{- FOURMOLU_DISABLE -}
data UpdateState a =
UpdateState
{ usUpdateAction_ :: IO a
{ usUpdateAction_ :: a -> IO a
, usLastResult_ :: IORef a
, usIntervalMicro_ :: Int
, usTimeHasCome_ :: TVar Bool
Expand All @@ -136,7 +136,7 @@ mkDeleteTimeout thc micro = do
openUpdateState :: UpdateSettings a -> IO (UpdateState a)
openUpdateState UpdateSettings{..} = do
thc <- newTVarIO False
UpdateState updateAction
UpdateState (const updateAction)
<$> (newIORef =<< updateAction)
<*> pure updateFreq
<*> pure thc
Expand All @@ -158,6 +158,6 @@ onceOnTimeHasCome UpdateState{..} action = do
getUpdateResult :: UpdateState a -> IO a
getUpdateResult us@UpdateState{..} = do
onceOnTimeHasCome us $ do
writeIORef usLastResult_ =<< usUpdateAction_
writeIORef usLastResult_ =<< usUpdateAction_ =<< readIORef usLastResult_
writeIORef usDeleteTimeout_ =<< mkDeleteTimeout usTimeHasCome_ usIntervalMicro_
readIORef usLastResult_

0 comments on commit 943bd7c

Please sign in to comment.