View Source DebounceAndThrottle.Debounce (Debounce and Throttle v0.9.0)

This module implements the Debounce API.

Link to this section Summary

Functions

Calls a fun but only after period has passed without any more calls to this function with the same key

Calls a fun but only after period has passed without any more calls to this function with the same key

Sends a message to a given pid, but only after period has passed without any more calls to this function with the same key

Returns the state - the current list of debounced functions. Useful for debugging.

Link to this section Types

Specs

t() :: %DebounceAndThrottle.Debounce{
  debounced_count: non_neg_integer(),
  extra_data: map(),
  scheduled_at: DateTime.t(),
  timer_ref: reference()
}

Link to this section Functions

Link to this function

apply(module, fun, args, key, period)

View Source

Specs

apply(module(), fun :: atom(), [any()], String.t(), non_neg_integer()) ::
  {:ok, t()}

Calls a fun but only after period has passed without any more calls to this function with the same key

Returns {:ok, %Debounce{}}.

Specs

call((... -> any()), String.t(), non_neg_integer()) :: {:ok, t()}

Calls a fun but only after period has passed without any more calls to this function with the same key

Returns {:ok, %Debounce{}}.

Link to this function

send(pid, message, key, period)

View Source

Specs

send(pid() | atom(), term(), String.t(), non_neg_integer()) :: {:ok, t()}

Sends a message to a given pid, but only after period has passed without any more calls to this function with the same key

Returns {:ok, %Debounce{}}.

Specs

state() :: map()

Returns the state - the current list of debounced functions. Useful for debugging.

Returns something like: %{ apply: %{}, call: %{

"say_hey" => %DebounceAndThrottle.Debounce{
  debounced_count: 1,
  extra_data: %{fun: #Function<45.65746770/0 in :erl_eval.expr/5>},
  scheduled_at: ~U[2022-03-12 22:50:01.190171Z],
  timer_ref: #Reference<0.418177534.3850108929.259344>
}

}, send: %{} }