View Source Cldr.Eternal (Cldr Currencies v2.16.0)
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.
Functionally equivalent to start_link/3
, except that the link to the starting
process is removed after the table is started.
Creates a new ETS table using the provided ets_opts
.
Terminates both servers in charge of a given ETS table.
Types
@type table() :: :ets.table()
Functions
Returns the heir of a given ETS table.
Examples
iex> Cldr.Eternal.heir(:my_table)
Returns the owner of a given ETS table.
Examples
iex> Cldr.Eternal.owner(:my_table)
Functionally equivalent to start_link/3
, except that the link to the starting
process is removed after the table is started.
Examples
iex> Cldr.Eternal.start(:table1, [], [quiet: true])
iex> Cldr.Eternal.start(:table2, [:compressed], [quiet: true])
iex> Cldr.Eternal.start(:table3, [], [quiet: true])
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:
:name
- override the default naming scheme and use a custom name for this table. Remember to use this name when callingstop/1
.:quiet
- by default, Eternal logs debug messages. Setting this to true will disable this logging.
Examples
iex> Cldr.Eternal.start_link(:table1, [], [quiet: true])
iex> Cldr.Eternal.start_link(:table2, [:compressed], [quiet: true])
iex> Cldr.Eternal.start_link(:table3, [], [quiet: true])
@spec stop(table :: table()) :: :ok
Terminates both servers in charge of a given ETS table.
Note: this will terminate your ETS table.
Examples
iex> Cldr.Eternal.stop(:my_table)
:ok