michalmuskala/debounce


A process-based debouncer for Elixir

License: Other

Language: Elixir


Debounce

A process-based debouncer for Elixir.

Full documentation can be found at https://hexdocs.pm/debounce

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

Installation

The package can be installed by adding debounce to your list of dependencies in mix.exs:

def deps do
  [{:debounce, "~> 0.1.0"}]
end

Project Statistics

Sourcerank 5
Repository Size 19.5 KB
Stars 13
Forks 0
Watchers 1
Open issues 0
Dependencies 0
Contributors 1
Tags 2
Created
Last updated
Last pushed

Top Contributors See all

MichaƂ MuskaƂa

Packages Referencing this Repo

debounce
A process-based debouncer for Elixir
Latest release 1.0.0 - Updated - 13 stars

Recent Tags See all

v0.1.1 January 10, 2017
v0.1.0 January 09, 2017

Something wrong with this page? Make a suggestion

Last synced: 2020-09-18 23:58:33 UTC

Login to resync this repository