View Source MySlowThrottler (Buffy v2.3.0)
Summary
Functions
Returns a specification to start this module under a supervisor.
Returns the maximum amount of jitter in milliseconds. This allows
for a bit of random delay before calling the throttle/1 function
to avoid thundering herd problems.
Returns the amount of throttle in milliseconds to wait before calling
the throttle/1 function. This function can be overridden to provide
dynamic throttling based on the passed in arguments.
The function that runs after throttle has completed. This function will
be called with the t:Buffy.Throttle.key() and can return anything. The
return value is ignored. If an error is raised, it will be logged and
ignored.
Starts debouncing the given t:Buffy.Throttle.key() for the
module set throttle time. Returns a tuple containing :ok
and the t:pid() of the throttle process.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec get_jitter(Buffy.Throttle.args()) :: non_neg_integer()
Returns the maximum amount of jitter in milliseconds. This allows
for a bit of random delay before calling the throttle/1 function
to avoid thundering herd problems.
@spec get_throttle(Buffy.Throttle.args()) :: non_neg_integer()
Returns the amount of throttle in milliseconds to wait before calling
the throttle/1 function. This function can be overridden to provide
dynamic throttling based on the passed in arguments.
@spec handle_throttle(Buffy.Throttle.args()) :: any()
The function that runs after throttle has completed. This function will
be called with the t:Buffy.Throttle.key() and can return anything. The
return value is ignored. If an error is raised, it will be logged and
ignored.
Examples
A simple example of implementing the Buffy.Throttle.handle_throttle/1
callback:
def handle_throttle(args) do
  # Do some work
endHandling errors in the Buffy.Throttle.handle_throttle/1 callback:
def handle_throttle(args) do
  # Do some work
rescue
  e ->
    # Do something with a raised error
end
  @spec throttle(Buffy.Throttle.args()) :: :ok | {:error, term()}
Starts debouncing the given t:Buffy.Throttle.key() for the
module set throttle time. Returns a tuple containing :ok
and the t:pid() of the throttle process.
Examples
iex> throttle(:my_function_arg)
{:ok, #PID<0.123.0>}