View Source Debouncex (Debouncex v0.1.0)

A process debouncex for Elixir.

What is debounce?

Debounce will call function with delay timeout, but if function is called multiple time with delay period, the time is reset and delay is counted again. Like debounce in Javascript but for Elixir.

Example

iex> defmodule Hello do
   def hello do
    :world
  end
end

iex> {:ok, pid} = Debouncex.start_link({
  &Hello.hello/0,
  [],
  1000
})

iex> Debouncex.call(pid) # Scheduler call after 1s
iex> :timer.sleep(100)
iex> Debouncex.call(pid) # Scheduler call after 1s
iex> :world

Link to this section Summary

Functions

Call function with delay timeout.

Cancel current debounce.

Change timeout delay call function.

Returns a specification to start this module under a supervisor.

Immediately invokes the function.

Callback implementation for GenServer.init/1.

Start Debounce process linked to current process.

Stop current process Debounce

Link to this section Types

@type arg() :: {function(), keyword(), timeout :: Millisecond}
@type name() :: atom()
@type server() :: pid() | name()

Link to this section Functions

@spec call(server :: server()) :: :ok

Call function with delay timeout.

@spec cancel(server :: server()) :: :ok

Cancel current debounce.

Link to this function

change_timeout(server, timeout)

View Source
@spec change_timeout(server :: server(), [{:timeout, Millisecond}]) :: :ok

Change timeout delay call function.

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec flush(server :: server()) :: :ok

Immediately invokes the function.

Callback implementation for GenServer.init/1.

Link to this function

start_link(init_arg, opts \\ [])

View Source
@spec start_link(init_arg :: arg(), opts :: keyword()) :: {:ok, pid()}

Start Debounce process linked to current process.

Delay call function until after timeout millisecond have elapsed after last time function call.

options

Options

@spec stop(server :: server()) :: :ok

Stop current process Debounce