debounce v0.1.1 Debounce
A process-based debouncer for Elixir.
What is a debouncer?
A debouncer is responsible for calling a function with a delay, but if that function is called multiple times within the delay period, the time is reset and delay is counted again. In other words, the function will be called after a delay period has elapsed from the last application.
Each time, the debounced function is called, a new task is started.
Example
iex> {:ok, pid} = Debounce.start_link({Kernel, :send, [self(), "Hello"]}, 100)
iex> Debounce.apply(pid) # Schedules call in 100 ms
iex> :timer.sleep(50)
iex> Debounce.apply(pid) # Resets timer back to 100 ms
iex> :timer.sleep(100)
iex> receive do msg -> msg end
"Hello" # Timer elapsed
iex> Debounce.apply(pid) # Schedules call in 100 ms
iex> Debounce.cancel(pid) # Cancels scheduled call
:ok
Summary
Functions
Schedules call to the current debouncer
’s function
Cancels any scheduled call to the current debouncer
’s function
Changes the function the debouncer
is applying
Changes the delay the debouncer
operates with
Immediately invokes the current debouncer
’s function
Starts a Debounce
process without links (outside of a supervision tree)
Starts a Debounce
process linked to the current process
Synchronously stops the debouncer with the given reason
Types
Functions
Schedules call to the current debouncer
’s function.
If the function is a fun, calls it with provided args
.
If the function is an mfargs/0
tuple, appends provided args
to the original ones.
If this function is called again withing the current debouncer
’s timeout
value, the time will reset.
Cancels any scheduled call to the current debouncer
’s function.
Changes the function the debouncer
is applying.
Affects only future calls to apply/2
.
Changes the delay the debouncer
operates with.
Affects only future calls to apply/2
.
Immediately invokes the current debouncer
’s function.
If the function is a fun, calls it with provided args
.
If the function is an mfargs/0
tuple, appends provided args
to the original ones.
Starts a Debounce
process without links (outside of a supervision tree).
See start_link/3
for more information.
Starts a Debounce
process linked to the current process.
This can be used to start the Debounce
as part of a supervision tree.
Delays invoking apply
until after timeout
millisecnds have elapsed
since the last time the apply/2
function was called.
Options
:name
- used for name registration, like inGenServer.start_link/3
.- all other options supported by
:gen_statem.start_link/4
stop(debouncer, reason :: term, timeout) :: :ok
Synchronously stops the debouncer with the given reason
.