beryl_heirloom
Typed ETS tables, heirs, and ownership transfers.
Access
Section titled “Access”pub type Access { Private Protected Public}The ETS table access level.
CreateError
Section titled “CreateError”pub type CreateError { TableAlreadyExists InvalidName InvalidHeir InvalidOptions}An error returned while creating a table.
pub type Heir(a) { NoHeir Heir( process: process.Pid, data: a )}The process that inherits a table when its owner exits.
OwnershipError
Section titled “OwnershipError”pub type OwnershipError { OwnershipTableDoesNotExist NotOwner InvalidOwnershipHeir RecipientNotAlive RecipientNotLocal RecipientIsOwner}An error returned while changing table ownership.
pub type Spec(a)Options used to create a table.
pub type Table(a, b)An ETS table whose key and value types are tracked by Gleam.
ETS does not validate these types at runtime.
TableError
Section titled “TableError”pub type TableError { TableDoesNotExist AccessDenied}An error returned while accessing a table.
TableType
Section titled “TableType”pub type TableType { Set OrderedSet Bag DuplicateBag}The ETS table type.
Transfer
Section titled “Transfer”pub type Transfer(a, b, c) { Transfer( table: Table(a, b), previous_owner: process.Pid, data: c )}An ETS ownership transfer.
TransferDecodeError
Section titled “TransferDecodeError”pub type TransferDecodeError { InvalidTransferMessage InvalidTable InvalidPreviousOwner InvalidHeirData(List(decode.DecodeError))}An error returned while decoding an ETS-TRANSFER message.
Functions
Section titled “Functions”clear_heir
Section titled “clear_heir”pub fn clear_heir(Table(a, b)) -> Result(Nil, OwnershipError)Clear the table heir.
The caller must own the table.
create
Section titled “create”pub fn create(Spec(a)) -> Result(Table(b, c), CreateError)Create an ETS table owned by the calling process.
Invalid UTF-8 or names longer than 255 Unicode code points return
InvalidName, for both named and unnamed tables.
Unnamed tables use the fixed atom beryl_heirloom for native
ets:info(Table, name) metadata, not the configured label. The returned
handle identifies the table instance.
delete
Section titled “delete”pub fn delete(Table(a, b)) -> Result(Nil, TableError)Delete a table owned by the calling process.
exists
Section titled “exists”pub fn exists(Table(a, b)) -> BoolReturn whether a table currently exists.
give_away
Section titled “give_away”pub fn give_away( Table(a, b), to: process.Pid, data: c) -> Result(Nil, OwnershipError)Give the table to another live local process.
The caller must own the table. The recipient observes completion through
an ETS-TRANSFER message. The configured heir is unchanged.
If the recipient exits before ETS transfers ownership, this returns
RecipientNotAlive and the caller keeps the table.
pub fn heir(Table(a, b)) -> Result(option.Option(process.Pid), TableError)Return the configured live heir, if present.
insert
Section titled “insert”pub fn insert( Table(a, b), a, b) -> Result(Nil, TableError)Insert or replace a key and value.
lookup
Section titled “lookup”pub fn lookup( Table(a, b), a) -> Result(option.Option(b), TableError)Look up one value for a key.
Set tables contain at most one value. Bag tables return the first value reported by ETS.
pub fn owner(Table(a, b)) -> Result(process.Pid, TableError)Return the current table owner.
select_transfers
Section titled “select_transfers”pub fn select_transfers( process.Selector(a), decode.Decoder(b), fn(Result(Transfer(c, d, b), TransferDecodeError)) -> a) -> process.Selector(a)Add typed ETS ownership transfers to a process selector.
Transfers produced by this module carry a private native gift envelope
containing the original table identity. The data decoder receives only the
original gift. A deleted original table returns InvalidTable, even if its
name has been reused.
Untagged native transfers carrying a live TID remain supported. Untagged
name-only transfers return InvalidTable: a name cannot prove which table
instance sent the message. The private envelope tag is reserved.
set_heir
Section titled “set_heir”pub fn set_heir( Table(a, b), process.Pid, c) -> Result(Nil, OwnershipError)Set the table heir.
The caller must own the table. The heir must be a live local process.
pub fn spec( String, TableType) -> Spec(Nil)Create a table specification with protected access and no heir.
Tables are unnamed by default. Creation validates the label without converting it to an atom.
with_access
Section titled “with_access”pub fn with_access( Spec(a), Access) -> Spec(a)Set the table access level.
with_heir
Section titled “with_heir”pub fn with_heir( Spec(a), process.Pid, b) -> Spec(b)Configure a live local process as the table heir.
with_named_table
Section titled “with_named_table”pub fn with_named_table(Spec(a)) -> Spec(a)Register the table under its configured name.
Creation converts the name to a permanent VM atom. Use a fixed, finite set of names; do not derive names from requests or job identifiers.
with_read_concurrency
Section titled “with_read_concurrency”pub fn with_read_concurrency( Spec(a), Bool) -> Spec(a)Enable or disable ETS read concurrency optimization.
with_write_concurrency
Section titled “with_write_concurrency”pub fn with_write_concurrency( Spec(a), Bool) -> Spec(a)Enable or disable ETS write concurrency optimization.
without_heir
Section titled “without_heir”pub fn without_heir(Spec(a)) -> Spec(Nil)Remove the configured heir.
