https://github.com/michalmuskala/debounce
A process-based debouncer for Elixir
https://github.com/michalmuskala/debounce
Last synced: 12 days ago
JSON representation
A process-based debouncer for Elixir
- Host: GitHub
- URL: https://github.com/michalmuskala/debounce
- Owner: michalmuskala
- License: other
- Created: 2017-01-09T23:43:10.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-09-18T19:16:34.000Z (over 4 years ago)
- Last Synced: 2024-10-30T00:24:59.588Z (6 months ago)
- Language: Elixir
- Size: 19.5 KB
- Stars: 23
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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
```elixir
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`:```elixir
def deps do
[{:debounce, "~> 0.1.0"}]
end
```