Debouncer v0.1.2 Debouncer 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
apply(key, fun, timeout \\ 5000)
View Sourceapply(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
cancel() deletes the latest event if it hasn't triggered yet.
Returns a specification to start this module under a supervisor.
See Supervisor
.
delay(key, fun, timeout \\ 5000)
View Sourcedelay(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
immediate(key, fun, timeout \\ 5000)
View Sourceimmediate(term(), (() -> any()), non_neg_integer()) :: :ok
immediate() executes the function immediately but blocks any further call
under the same key for the given timeout.
immediate2(key, fun, timeout \\ 5000)
View Sourceimmediate2(term(), (() -> any()), non_neg_integer()) :: :ok
immediate2() executes the function immediately but blocks any further call
under the same key for the given timeout.