View Source Debouncer (Debouncer v0.1.7)
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/3
=> Events are executed after the timeoutimmediate/3
=> Events are executed immediately, and further events are delayed for the timeoutimmediate2/3
=> Events are executed immediately, and further events are IGNORED for the timeoutdelay/3
=> 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
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
Deletes the latest event if it hasn't triggered yet.
Returns a specification to start this module under a supervisor.
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
Executes the function immediately but ignores further calls under the same key for the given timeout.
Executes the function immediately but blocks any further call under the same key for the given timeout.
Link to this section Functions
@spec apply(term(), (() -> any()), non_neg_integer()) :: :ok
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
@spec cancel(term()) :: :ok
Deletes the latest event if it hasn't triggered yet.
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec delay(term(), (() -> any()), non_neg_integer()) :: :ok
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
@spec immediate2(term(), (() -> any()), non_neg_integer()) :: :ok
Executes the function immediately but ignores further calls under the same key for the given timeout.
@spec immediate(term(), (() -> any()), non_neg_integer()) :: :ok
Executes the function immediately but blocks any further call under the same key for the given timeout.