From 643639f01cb94a4e663338aabdd9dd9c35d738b0 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Fri, 11 Sep 2026 11:26:12 +0200 Subject: fix the debouncing logic --- Main.hs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Main.hs b/Main.hs index 7c27afe..4f0d399 100644 --- a/Main.hs +++ b/Main.hs @@ -169,9 +169,9 @@ main = do , stAddsPending = succ stAddsPending , stPushesPending = succ stPushesPending } - AddBounce -- TODO the last trigger looks nice but may cause double add, instead track an increasing token or such + AddBounce | not (S.null stWatch) - , stAddsPending == 1 + , stAddsPending == 1 {- protection against triggering too early -} || intervalPassed (optAddCommitDelay o) now stLastAdd -> do for_ stWatch $ \w@(Watch p addAll) -> do dbg $ "will add: " ++ show w @@ -186,25 +186,28 @@ main = do st { stWatch = S.empty , stLastAdd = now - , stAddsPending = pred stAddsPending + , stAddsPending = 0 , stCommitSeries = succ stCommitSeries } | otherwise -> - loop st {stWatch = S.empty, stAddsPending = pred stAddsPending} + loop + st + { stWatch = S.empty + , stAddsPending = 0 `max` pred stAddsPending + } PushBounce | Just pd <- optPushDelay o , stPushesPending == 1 || intervalPassed pd now stLastPush -> do dbg $ "push!" runCmd git ["push"] + loop + st {stWatch = S.empty, stLastPush = now, stPushesPending = 0} + | otherwise -> loop st { stWatch = S.empty - , stLastPush = now - , stPushesPending = pred stPushesPending + , stPushesPending = 0 `max` pred stPushesPending } - | otherwise -> - loop - st {stWatch = S.empty, stPushesPending = pred stPushesPending} void . forkIO $ loop emptyState -- wait for the finish, then terminate takeMVar done -- cgit v1.2.3