Control.Debounce.Internal

auto-update-0.2.6: Efficiently run periodic, on-demand actions

Safe Haskell | None
Language | Haskell2010

Control.Debounce.Internal

Description

Unstable API which exposes internals for testing.

Synopsis

- data DebounceSettings = DebounceSettings {
  - debounceFreq :: Int
  - debounceAction :: IO ()
  - debounceEdge :: DebounceEdge
  - debounceThreadName :: String
  }
- data DebounceEdge
  - = Leading
  - | LeadingMute
  - | Trailing
  - | TrailingDelay
- leadingEdge :: DebounceEdge
- leadingMuteEdge :: DebounceEdge
- trailingEdge :: DebounceEdge
- trailingDelayEdge :: DebounceEdge
- mkDebounceInternal :: MVar () -> (Int -> IO ()) -> DebounceSettings -> IO (IO ())

# Documentation

data DebounceSettings #

Settings to control how debouncing should work.

This should be constructed using `defaultDebounceSettings` and record update syntax, e.g.:

    let settings = defaultDebounceSettings { debounceAction = flushLog }

Since: 0.1.2

Constructors

DebounceSettings |
Fields debounceFreq :: Int Length of the debounce timeout period in microseconds. Default: 1 second (1000000) Since: 0.1.2 debounceAction :: IO () Action to be performed. Note: all exceptions thrown by this action will be silently discarded. Default: does nothing. Since: 0.1.2 debounceEdge :: DebounceEdge Whether to perform the action on the leading edge or trailing edge of the timeout. Default: `leadingEdge`. Since: 0.1.6 debounceThreadName :: String Label of the thread spawned when debouncing. Default: `Debounce`. Since: 0.2.2

data DebounceEdge #

Setting to control whether the action happens at the leading and/or trailing edge of the timeout.

Since: 0.1.6

Constructors

Leading | Perform the action immediately, and then begin a cooldown period. If the trigger happens again during the cooldown, wait until the end of the cooldown and then perform the action again, then enter a new cooldown period.
LeadingMute | Perform the action immediately, and then begin a cooldown period. If the trigger happens again during the cooldown, it is ignored.
Trailing | Start a cooldown period and perform the action when the period ends. If another trigger happens during the cooldown, it has no effect.
TrailingDelay | Start a cooldown period and perform the action when the period ends. If another trigger happens during the cooldown, it restarts the cooldown again.

#### Instances

Instances details

Show DebounceEdge # |
Instance details Defined in Control.Debounce.Internal Methods showsPrec :: Int -> DebounceEdge -> ShowS # show :: DebounceEdge -> String # showList :: [DebounceEdge] -> ShowS #
Eq DebounceEdge # |
Instance details Defined in Control.Debounce.Internal Methods (==) :: DebounceEdge -> DebounceEdge -> Bool # (/=) :: DebounceEdge -> DebounceEdge -> Bool #

leadingEdge :: DebounceEdge #

Perform the action immediately, and then begin a cooldown period. If the trigger happens again during the cooldown, wait until the end of the cooldown and then perform the action again, then enter a new cooldown period.

Example of how this style debounce works:

    ! = function execution
    . = cooldown period
    X = debounced code execution

    !   !         !            !
     ....... ....... .......    .......
    X       X       X          X

Since: 0.1.6

leadingMuteEdge :: DebounceEdge #

Perform the action immediately, and then begin a cooldown period. If the trigger happens again during the cooldown, it is ignored.

Example of how this style debounce works:

    ! = function execution
    . = cooldown period
    X = debounced code execution

    !   !      !     !
     .......    .......
    X          X

Since: 0.1.6

trailingEdge :: DebounceEdge #

Start a cooldown period and perform the action when the period ends. If another trigger happens during the cooldown, it has no effect.

Example of how this style debounce works:

    ! = function execution
    . = cooldown period
    X = debounced code execution

    !     !     !  !
     .......     .......
            X           X

Since: 0.1.6

trailingDelayEdge :: DebounceEdge #

Start a cooldown period and perform the action when the period ends. If another trigger happens during the cooldown, it restarts the cooldown again.

N.B. If a trigger happens DURING the `debounceAction` it starts a new cooldown. So if the `debounceAction` takes longer than the `debounceFreq`, it might run again before the previous action has ended.

Example of how this style debounce works:

    ! = function execution
    . = cooldown period
    X = debounced code execution

    !           !  !    !
     .......     ...............
            X                   X

Since: 0.1.6

mkDebounceInternal :: MVar () -> (Int -> IO ()) -> DebounceSettings -> IO (IO ()) #