Debouncer (Debouncer v0.1.5) View Source

Debouncer executes a function call debounced. Debouncing is done one a per key basis:

    Debouncer.apply(Key, fn() -> IO.puts("Hello World, debounced") end)

The third optional parameter is the timeout period in milliseconds

    Debouncer.apply(Key, fn() -> IO.puts("Hello World, once per minute max") end, 60_000)

The variants supported are:

  • apply() => Events are executed after the timeout
  • immediate() => Events are executed immediately, and further events are delayed for the timeout
  • immediate2() => Events are executed immediately, and further events are IGNORED for the timeout
  • delay() => Each event delays the execution of the next event
  EVENT        X1---X2------X3-------X4----------
  TIMEOUT      ----------|----------|----------|-
  ===============================================
  apply()      ----------X2---------X3---------X4
  immediate()  X1--------X2---------X3---------X4
  immediate2() X1-----------X3-------------------
  delay()      --------------------------------X4

Link to this section Summary

Functions

apply() executes the function after the specified timeout t0 + timeout,

cancel() deletes the latest event if it hasn't triggered yet.

Returns a specification to start this module under a supervisor.

delay() executes the function after the specified timeout t0 + timeout,

immediate() executes the function immediately but blocks any further call

immediate2() executes the function immediately but blocks any further call

Link to this section Functions

Link to this function

apply(key, fun, timeout \\ 5000)

View Source

Specs

apply(term(), (() -> any()), non_neg_integer()) :: :ok

apply() executes the function after the specified timeout t0 + timeout,

when apply is called multiple times it does not affect the point
in time when the next call is happening (t0 + timeout) but updates the fun

Specs

cancel(term()) :: :ok

cancel() deletes the latest event if it hasn't triggered yet.

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

delay(key, fun, timeout \\ 5000)

View Source

Specs

delay(term(), (() -> any()), non_neg_integer()) :: :ok

delay() executes the function after the specified timeout t0 + timeout,

when delay is called multipe times the timeout is reset based on the
most recent call (t1 + timeout, t2 + timeout) etc... the fun is also updated
Link to this function

immediate(key, fun, timeout \\ 5000)

View Source

Specs

immediate(term(), (() -> any()), non_neg_integer()) :: :ok

immediate() executes the function immediately but blocks any further call

under the same key for the given timeout.
Link to this function

immediate2(key, fun, timeout \\ 5000)

View Source

Specs

immediate2(term(), (() -> any()), non_neg_integer()) :: :ok

immediate2() executes the function immediately but blocks any further call

under the same key for the given timeout.