@@ -1,9 +1,10 @@
11{-# LANGUAGE ScopedTypeVariables #-}
22
3+-- | Unstable API which exposes internals for testing.
34module Control.Debounce.Internal (
45 DebounceSettings(..)
56 , DebounceEdge(..)
6− , mkDebounce
7+ , mkDebounceInternal
78 ) where
89
910import Control.Concurrent (forkIO)
@@ -44,9 +45,13 @@ data DebounceSettings = DebounceSettings
4445 --
4546 -- Default: Leading.
4647 --
47− -- @since 0.2.0
48+ -- @since 0.1.6
4849 }
4950
51+-- | Setting to control whether the action happens at the leading or trailing
52+-- edge of the timeout.
53+--
54+-- @since 0.1.6
5055data DebounceEdge =
5156 Leading
5257 -- ^ The action will either be performed immediately, or after the current cooldown period has expired.
@@ -57,16 +62,18 @@ data DebounceEdge =
5762 -- the debounced function was invoked again during the cooldown.
5863 deriving (Show, Eq)
5964
60−mkDebounce :: MVar () -> (Int -> IO ()) -> DebounceSettings -> IO (IO ())
61−mkDebounce baton delayFn (DebounceSettings freq action edge) = do
65+mkDebounceInternal :: MVar () -> (Int -> IO ()) -> DebounceSettings -> IO (IO ())
66+mkDebounceInternal baton delayFn (DebounceSettings freq action edge) = do
6267 mask_ $ void $ forkIO $ forever $ do
6368 takeMVar baton
64− if edge `elem` [Leading, LeadingAndTrailing] then ignoreExc action >> runDelay False baton
65− else runDelay True baton
69+ case edge of
70+ Leading -> ignoreExc action >> runDelay False
71+ LeadingAndTrailing -> ignoreExc action >> runDelay False
72+ Trailing -> runDelay True
6673
6774 return $ void $ tryPutMVar baton ()
6875
69− where runDelay hasDelayedInitialActivation baton = do
76+ where runDelay hasDelayedInitialActivation = do
7077 delayFn freq
7178
7279 case edge of