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:
- An ETS table is created with the provided name and options.
- Two GenServers are started, an
owner
and anheir
. The ETS table is gifted to theowner
, and has theheir
set as the heir. - If the
owner
crashes, theheir
becomes the owner, and a new GenServer is started and assigned the role ofheir
. - If an
heir
dies, we attempt to start a new GenServer and notify theowner
so that they may change the assignedheir
.
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
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>
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>
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 }