Dispenser.Server.BufferServer (dispenser v0.1.0) View Source

A BufferServer is an example GenServer that uses Dispenser.Buffer. It can receive events and send them to subscriber processes.

Subscribers can control the flow by telling the BufferServer how many events they want, using ask/3. See ask/3 for more information about how events are sent to subscribers.

Link to this section Summary

Types

The arguments required to create a BufferServer.

The opaque internal state of the BufferServer.

Functions

Add events to the BufferServer.

Ask for events from the BufferServer.

Returns a specification to start this module under a supervisor.

Start a new BufferServer GenServer.

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

Unsubscribe from the BufferServer.

Link to this section Types

Specs

init_args(event) :: %{buffer: Dispenser.Buffer.t(event, pid())}

The arguments required to create a BufferServer.

:buffer defines the Buffer used internally by the BufferServer.

See start_link/1.

Specs

t(event)

The opaque internal state of the BufferServer.

Link to this section Functions

Specs

append(GenServer.server(), [event]) :: {:ok, dropped :: non_neg_integer()}
when event: any()

Add events to the BufferServer.

If the buffer reaches its capacity, an error is returned with the number of events that were were dropped.

Specs

Ask for events from the BufferServer.

Events will be delivered asynchronously to the subscribed pid in the shape of:

{:handle_assigned_events, sender, events}

where:

  • sender is the pid of this BufferServer.
  • events is a list of events that were appended to the BufferServer.
Link to this function

ask(server, subscriber, amount)

View Source

Specs

ask(GenServer.server(), subscriber :: pid(), non_neg_integer()) :: :ok

Returns a specification to start this module under a supervisor.

See Supervisor.

Specs

start_link(init_args(event)) :: {:ok, pid()} | {:error, term()}
when event: any()

Start a new BufferServer GenServer.

See init_args/0 and GenServer.start_link/2

Specs

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

Specs

unsubscribe(GenServer.server()) :: :ok | {:error, :not_subscribed}

Unsubscribe from the BufferServer.

Link to this function

unsubscribe(server, subscriber)

View Source

Specs

unsubscribe(GenServer.server(), pid()) :: :ok | {:error, :not_subscribed}