Dispenser.Demands (dispenser v0.1.0) View Source

Tracks the demands of subscribers.

Keeps a constant-time total/1 of the overall demand.

Used by Buffer to keep track of demand for events.

Used by implementations of Dispenser.AssignmentStrategy to determine which subscribers to send to.

Link to this section Summary

Types

The current demand for one subscriber.

A map of all subscribers that have demand > 0, with their demands.

The opaque internal state of the Demands.

Functions

Add some demand for one subscriber. A subscriber can demand as much as it wants.

Remove the demand of one subscriber.

Get the current demand for one subscriber.

Create a new Demands.

The total number of subscribers that have demand > 0.

Get all subscribers that have demand > 0.

Remove some demand for one subscriber.

The total demand of all subscribers.

Link to this section Types

Specs

demand() :: pos_integer()

The current demand for one subscriber.

Link to this type

subscribers(subscriber)

View Source

Specs

subscribers(subscriber) :: %{required(subscriber) => demand()}

A map of all subscribers that have demand > 0, with their demands.

Specs

t(subscriber)

The opaque internal state of the Demands.

Link to this section Functions

Link to this function

add(state, subscriber, amount)

View Source

Specs

add(t(subscriber), subscriber, non_neg_integer()) :: t(subscriber)
when subscriber: any()

Add some demand for one subscriber. A subscriber can demand as much as it wants.

Link to this function

delete(state, subscriber)

View Source

Specs

delete(t(subscriber), subscriber) :: t(subscriber) when subscriber: any()

Remove the demand of one subscriber.

Specs

get(t(subscriber), subscriber) :: non_neg_integer() when subscriber: any()

Get the current demand for one subscriber.

Specs

new() :: t(subscriber) when subscriber: any()

Create a new Demands.

Specs

size(t(subscriber)) :: non_neg_integer() when subscriber: any()

The total number of subscribers that have demand > 0.

Specs

subscribers(t(subscriber)) :: subscribers(subscriber) when subscriber: any()

Get all subscribers that have demand > 0.

Link to this function

subtract(state, subscriber, amount)

View Source

Specs

subtract(t(subscriber), subscriber, non_neg_integer()) :: t(subscriber)
when subscriber: any()

Remove some demand for one subscriber.

Once a subscriber reaches 0 demand, it is no longer tracked by Demands.

Specs

total(t(subscriber)) :: non_neg_integer() when subscriber: any()

The total demand of all subscribers.