Eternal v1.1.0 Eternal

This module implements bindings around what should be an eternal ETS table, or at least until you decide to terminate it. It works by using “bouncing” GenServers which come up as needed to provide an heir for the ETS table. It operates as follows:

  1. An ETS table is created with the provided name and options.
  2. Two GenServers are started, an owner and an heir. The ETS table is gifted to the owner, and has the heir set as the heir.
  3. If the owner crashes, the heir becomes the owner, and a new GenServer is started and assigned the role of heir.
  4. If an heir dies, we attempt to start a new GenServer and notify the owner so that they may change the assigned heir.

This means that there should always be an heir to your table, which should ensure that you don’t lose anything inside ETS.

Summary

Functions

Returns the heir of a given ETS table

Returns the owner of a given ETS table

Creates a new ETS table using the provided ets_opts

Terminates both servers in charge of a given ETS table

Types

on_start ::
  {:ok, pid} |
  :ignore |
  {:error, {:already_started, pid} | {:shutdown, term} | term}

Functions

heir(table)

Specs

heir(table :: Eternal.Table.t) :: pid | :undefined

Returns the heir of a given ETS table.

Examples

iex> Eternal.heir(:my_table)
#PID<0.134.0>
owner(table)

Specs

owner(table :: Eternal.Table.t) :: pid | :undefined

Returns the owner of a given ETS table.

Examples

iex> Eternal.owner(:my_table)
#PID<0.132.0>
start_link(name, ets_opts \\ [], opts \\ [])

Specs

start_link(name :: atom, ets_opts :: Keyword.t, opts :: Keyword.t) :: on_start

Creates a new ETS table using the provided ets_opts.

These options are passed through as-is, with the exception of prepending the :public and :named_table options. Seeing as you can’t execute inside the GenServers, your table will have to be public to be interacted with.

Options

You may provide a third parameter containing Eternal options:

  • :quiet - by default, Eternal logs debug messages. Setting this to true will disable this logging.

Examples

iex> Eternal.new(:table1)
{ :ok, _pid1 }

iex> Eternal.new(:table2, [ :compressed ])
{ :ok, _pid2 }

iex> Eternal.new(:table3, [ ], [ quiet: true ])
{ :ok, _pid3 }
stop(table)

Specs

stop(table :: Eternal.Table.t) :: :ok

Terminates both servers in charge of a given ETS table.

Note: this will terminate your ETS table.

Examples

iex> Eternal.stop(:my_table)
:ok