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

Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Debounce

Contents

Description

Debounce an action, ensuring it doesn't occur more than once for a given period of time.

This is useful as an optimization, for example to ensure that logs are only flushed to disk at most once per second. See the fast-logger package for an example usage.

Since 0.1.2

Synopsis

Type

data DebounceSettings Source

Settings to control how debouncing should work.

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

let set = defaultDebounceSettings { debounceAction = flushLog }

Since 0.1.2

defaultDebounceSettings :: DebounceSettings Source

Default value for creating a DebounceSettings.

Since 0.1.2

Accessors

debounceFreq :: DebounceSettings -> Int Source

Microseconds lag required between subsequence calls to the debounced action.

Default: 1 second (1000000)

Since 0.1.2

debounceAction :: DebounceSettings -> IO () Source

Action to be performed.

Note: all exceptions thrown by this action will be silently discarded.

Default: does nothing.

Since 0.1.2

Creation

mkDebounce :: DebounceSettings -> IO (IO ()) Source

Generate an action which will trigger the debounced action to be performed. The action will either be performed immediately, or after the current cooldown period has expired.

Since 0.1.2