ETSBuffer (ETSBuffer v0.2.0) View Source

ETSBuffer is a simple buffer that stores a maximum of N events, keeping only the N events with the greatest sort keys.

ETSBuffer is backed by an ordered set ETS table, and thus the buffer is ordered using erlang term ordering of the sort key to determine which events are the greatest.

ETSBuffer also uses a protected, read concurrent optimized ETS table so that the buffer can be read concurrently by many processes, but must be updated through a single process.

Example


iex(1)> buffer = ETSBuffer.init(max_size: 5)

iex(1)> ETSBuffer.push(buffer, 1, 1)
iex(2)> ETSBuffer.push(buffer, 2, 2)
iex(3)> ETSBuffer.push(buffer, 3, 3)
iex(4)> ETSBuffer.push(buffer, 0, 0)
iex(5)> ETSBuffer.push(buffer, 6, 6)
iex(6)> ETSBuffer.push(buffer, 5, 5)

iex(7)> ETSBuffer.list()
[2,3,4,5,6]

Link to this section Summary

Link to this section Types

Specs

t() :: %ETSBuffer{max_size: integer(), table: nil | reference()}

Link to this section Functions

Specs

delete(t(), any()) :: :ok

Specs

destroy(t()) :: :ok

Specs

dump(t()) :: %{max_size: integer(), data: list()}

Specs

earliest_id(t()) :: any()

Specs

init(integer()) :: t()

Specs

latest_id(t()) :: any()

Specs

list(t()) :: list()
Link to this function

push(buffer, sort_key, event)

View Source

Specs

push(t(), any(), any()) :: :ok

Specs

replace(t(), list()) :: t()

Specs

restore(%{max_size: integer(), data: list()}) :: t()

Specs

size(t()) :: integer()