Dispenser.MonitoredBuffer (dispenser v0.1.0) View Source

A MonitoredBuffer contains most of the logic required to implement a GenServer that wraps a Buffer. MonitoredBuffer combines a Buffer to track events and a SubscriptionManager to track subscribers.

Link to this section Summary

Types

Various statistics exposed by the MonitoredBuffer for use by debugging and metrics.

The opaque internal state of the MonitoredBuffer.

Functions

Add events to the MonitoredBuffer.

Ask for events from the Buffer.

Given the current events and demands, returns the events to send to each subscriber.

Stop monitoring and remove all demand from the given subscriber.

Handle the down signal from a monitored subscriber.

Create a new MonitoredBuffer that wraps the given Buffer.

Get the number of events in the MonitoredBuffer.

Get various statistics about the MonitoredBuffer for use when debugging and generating metrics.

Link to this section Types

Specs

stats() :: %{
  buffered: non_neg_integer(),
  subscribed: non_neg_integer(),
  demand: non_neg_integer()
}

Various statistics exposed by the MonitoredBuffer for use by debugging and metrics.

See stats/1

Specs

t(event)

The opaque internal state of the MonitoredBuffer.

Link to this section Functions

Specs

append(t(event), [event]) :: {t(event), dropped :: non_neg_integer()}
when event: any()

Add events to the MonitoredBuffer.

If the MonitoredBuffer reaches its capacity, events will be dropped.

Link to this function

ask(state, subscriber, demand)

View Source

Specs

ask(t(event), subscriber :: pid(), demand :: non_neg_integer()) :: t(event)
when event: any()

Ask for events from the Buffer.

These demands are met by calls to assign_events/1

Specs

assign_events(t(event)) :: {t(event), [{subscriber :: pid(), [event]}]}
when event: any()

Given the current events and demands, returns the events to send to each subscriber.

Link to this function

delete(state, subscriber)

View Source

Specs

delete(t(event), subscriber :: pid()) ::
  {:ok, t(event)} | {:error, :not_subscribed}
when event: any()

Stop monitoring and remove all demand from the given subscriber.

Link to this function

down(state, subscriber, ref)

View Source

Specs

down(t(event), subscriber :: pid(), reference()) ::
  {:ok, t(event)} | {:error, :wrong_ref} | {:error, :not_subscribed}
when event: any()

Handle the down signal from a monitored subscriber.

Specs

new(Dispenser.Buffer.t(event, pid())) :: t(event) when event: any()

Create a new MonitoredBuffer that wraps the given Buffer.

Specs

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

Get the number of events in the MonitoredBuffer.

Specs

stats(t(event)) :: stats() when event: any()

Get various statistics about the MonitoredBuffer for use when debugging and generating metrics.