community_theatre v0.1.1 CommunityTheatre.RateLimiter behaviour

The RateLimiter behaviour allows you to define for yourself how you would like messages to be handled in the event that they arrive faster than required.

The behaviour specifies three callbacks;

  • init/1 which you can use for initialising your data structure,
  • merge/2 which you can use to update your data when new messages are received, and
  • get/1 which is called when it is time to send a message to a subscribee.

CommunityTheatre provides two rate limiters out of the box; but you can easily write your own if they don't meet your needs:

Link to this section Summary

Callbacks

Returns the next value that should be sent to a subscriber.

Called when creating a new rate limited subscription. Use this to initialise the data structure needed to keep state for rate limiting.

Called when a new message is received from a source so that you can update the limiter state.

Link to this section Types

Link to this section Callbacks

Link to this callback

get(t)

get(t()) :: {:ok, CommunityTheatre.Message.t() | nil, t()} | {:error, any()}

Returns the next value that should be sent to a subscriber.

Link to this callback

init(update_frequency)

init(update_frequency :: hz()) :: {:ok, t()} | {:error, any()}

Called when creating a new rate limited subscription. Use this to initialise the data structure needed to keep state for rate limiting.

Link to this callback

merge(t, arg2)

merge(t(), CommunityTheatre.Message.t()) :: {:ok, t()} | {:error, any()}

Called when a new message is received from a source so that you can update the limiter state.