View Source Siblings.Throttler (Siblings v0.11.0)

The internal definition of the call to throttle.

Siblings.Throttler.call/3 is a blocking call similar to GenServer.call/3, but served by the underlying GenStage producer-consumer pair.

Despite this implementation of throttling based on GenStage is provided mostly for internal needs, it is generic enough to use wherever. Use the childspec {Siblings.Throttler, name: name, initial: [], max_demand: 3, interval: 1_000} to start a throttling process and Siblings.Throttler.call/3 to perform throttled synchronous calls from different processes.

Link to this section Summary

Types

t()

The in/out parameter for calls to Siblings.Throttler.call/3

The simplified in parameter for calls to Siblings.Throttler.call/3

Functions

Synchronously executes the function, using throttling based on GenStage.

Returns a specification to start this module under a supervisor.

Starts the throttler with the underlying producer-consumer stages.

Link to this section Types

@type t() :: %Siblings.Throttler{
  from: GenServer.from(),
  fun: (keyword() -> any()),
  args: keyword(),
  result: any(),
  payload: any()
}

The in/out parameter for calls to Siblings.Throttler.call/3

@type throttlee() :: t() | {(keyword() -> any()), [any()]}

The simplified in parameter for calls to Siblings.Throttler.call/3

Link to this section Functions

Link to this function

call(name \\ Siblings.default_fqn(), request, timeout \\ :infinity)

View Source

Synchronously executes the function, using throttling based on GenStage.

This function has a default timeout :infinity because of its nature (throttling is supposed to take a while,) but it might be passed as the third argument in a call to call/3.

If a list of functions is given, executes all of them in parallel, collects the results, and then returns them to the caller.

The function might be given as t:Siblings.Throttler.t() or in a simplified form as {function_of_arity_1, arg}.

Returns a specification to start this module under a supervisor.

See Supervisor.

Starts the throttler with the underlying producer-consumer stages.

Accepted options are:

  • name the base name for the throttler to be used in calls to call/3
  • initial the initial load of requests (avoid using it unless really needed)
  • max_demand, initial the options to be passed directly to GenStage’s consumer